1 /*
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 // Optimization - Graph Style
26
27 #include "incls/_precompiled.incl"
28 #include "incls/_connode.cpp.incl"
29
30 //=============================================================================
31 //------------------------------hash-------------------------------------------
32 uint ConNode::hash() const {
33 return (uintptr_t)in(TypeFunc::Control) + _type->hash();
34 }
35
36 //------------------------------make-------------------------------------------
37 ConNode *ConNode::make( Compile* C, const Type *t ) {
38 switch( t->basic_type() ) {
39 case T_INT: return new (C, 1) ConINode( t->is_int() );
40 case T_LONG: return new (C, 1) ConLNode( t->is_long() );
41 case T_FLOAT: return new (C, 1) ConFNode( t->is_float_constant() );
42 case T_DOUBLE: return new (C, 1) ConDNode( t->is_double_constant() );
43 case T_VOID: return new (C, 1) ConNode ( Type::TOP );
44 case T_OBJECT: return new (C, 1) ConPNode( t->is_oopptr() );
45 case T_ARRAY: return new (C, 1) ConPNode( t->is_aryptr() );
46 case T_ADDRESS: return new (C, 1) ConPNode( t->is_ptr() );
47 case T_NARROWOOP: return new (C, 1) ConNNode( t->is_narrowoop() );
48 // Expected cases: TypePtr::NULL_PTR, any is_rawptr()
49 // Also seen: AnyPtr(TopPTR *+top); from command line:
50 // r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=660
51 // %%%% Stop using TypePtr::NULL_PTR to represent nulls: use either TypeRawPtr::NULL_PTR
52 // or else TypeOopPtr::NULL_PTR. Then set Type::_basic_type[AnyPtr] = T_ILLEGAL
53 }
54 ShouldNotReachHere();
55 return NULL;
56 }
57
58 //=============================================================================
59 /*
60 The major change is for CMoveP and StrComp. They have related but slightly
61 different problems. They both take in TWO oops which are both null-checked
62 independently before the using Node. After CCP removes the CastPP's they need
63 to pick up the guarding test edge - in this case TWO control edges. I tried
64 various solutions, all have problems:
65
66 (1) Do nothing. This leads to a bug where we hoist a Load from a CMoveP or a
67 StrComp above a guarding null check. I've seen both cases in normal -Xcomp
68 testing.
69
70 (2) Plug the control edge from 1 of the 2 oops in. Apparent problem here is
71 to figure out which test post-dominates. The real problem is that it doesn't
72 matter which one you pick. After you pick up, the dominating-test elider in
73 IGVN can remove the test and allow you to hoist up to the dominating test on
74 the choosen oop bypassing the test on the not-choosen oop. Seen in testing.
75 Oops.
76
77 (3) Leave the CastPP's in. This makes the graph more accurate in some sense;
78 we get to keep around the knowledge that an oop is not-null after some test.
79 Alas, the CastPP's interfere with GVN (some values are the regular oop, some
80 are the CastPP of the oop, all merge at Phi's which cannot collapse, etc).
81 This cost us 10% on SpecJVM, even when I removed some of the more trivial
82 cases in the optimizer. Removing more useless Phi's started allowing Loads to
83 illegally float above null checks. I gave up on this approach.
84
85 (4) Add BOTH control edges to both tests. Alas, too much code knows that
86 control edges are in slot-zero ONLY. Many quick asserts fail; no way to do
87 this one. Note that I really want to allow the CMoveP to float and add both
88 control edges to the dependent Load op - meaning I can select early but I
89 cannot Load until I pass both tests.
90
91 (5) Do not hoist CMoveP and StrComp. To this end I added the v-call
92 depends_only_on_test(). No obvious performance loss on Spec, but we are
93 clearly conservative on CMoveP (also so on StrComp but that's unlikely to
94 matter ever).
95
96 */
97
98
99 //------------------------------Ideal------------------------------------------
100 // Return a node which is more "ideal" than the current node.
101 // Move constants to the right.
102 Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
103 if( in(0) && remove_dead_region(phase, can_reshape) ) return this;
104 assert( !phase->eqv(in(Condition), this) &&
105 !phase->eqv(in(IfFalse), this) &&
106 !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
107 if( phase->type(in(Condition)) == Type::TOP )
108 return NULL; // return NULL when Condition is dead
109
110 if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {
111 if( in(Condition)->is_Bool() ) {
112 BoolNode* b = in(Condition)->as_Bool();
113 BoolNode* b2 = b->negate(phase);
114 return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
115 }
116 }
117 return NULL;
118 }
119
120 //------------------------------is_cmove_id------------------------------------
121 // Helper function to check for CMOVE identity. Shared with PhiNode::Identity
122 Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
123 // Check for Cmp'ing and CMove'ing same values
124 if( (phase->eqv(cmp->in(1),f) &&
125 phase->eqv(cmp->in(2),t)) ||
126 // Swapped Cmp is OK
127 (phase->eqv(cmp->in(2),f) &&
128 phase->eqv(cmp->in(1),t)) ) {
129 // Check for "(t==f)?t:f;" and replace with "f"
130 if( b->_test._test == BoolTest::eq )
131 return f;
132 // Allow the inverted case as well
133 // Check for "(t!=f)?t:f;" and replace with "t"
134 if( b->_test._test == BoolTest::ne )
135 return t;
136 }
137 return NULL;
138 }
139
140 //------------------------------Identity---------------------------------------
141 // Conditional-move is an identity if both inputs are the same, or the test
142 // true or false.
143 Node *CMoveNode::Identity( PhaseTransform *phase ) {
144 if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?
145 return in(IfFalse); // Then it doesn't matter
146 if( phase->type(in(Condition)) == TypeInt::ZERO )
147 return in(IfFalse); // Always pick left(false) input
148 if( phase->type(in(Condition)) == TypeInt::ONE )
149 return in(IfTrue); // Always pick right(true) input
150
151 // Check for CMove'ing a constant after comparing against the constant.
152 // Happens all the time now, since if we compare equality vs a constant in
153 // the parser, we "know" the variable is constant on one path and we force
154 // it. Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a
155 // conditional move: "x = (x==0)?0:x;". Yucko. This fix is slightly more
156 // general in that we don't need constants.
157 if( in(Condition)->is_Bool() ) {
158 BoolNode *b = in(Condition)->as_Bool();
159 Node *cmp = b->in(1);
160 if( cmp->is_Cmp() ) {
161 Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );
162 if( id ) return id;
163 }
164 }
165
166 return this;
167 }
168
169 //------------------------------Value------------------------------------------
170 // Result is the meet of inputs
171 const Type *CMoveNode::Value( PhaseTransform *phase ) const {
172 if( phase->type(in(Condition)) == Type::TOP )
173 return Type::TOP;
174 return phase->type(in(IfFalse))->meet(phase->type(in(IfTrue)));
175 }
176
177 //------------------------------make-------------------------------------------
178 // Make a correctly-flavored CMove. Since _type is directly determined
179 // from the inputs we do not need to specify it here.
180 CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) {
181 switch( t->basic_type() ) {
182 case T_INT: return new (C, 4) CMoveINode( bol, left, right, t->is_int() );
183 case T_FLOAT: return new (C, 4) CMoveFNode( bol, left, right, t );
184 case T_DOUBLE: return new (C, 4) CMoveDNode( bol, left, right, t );
185 case T_LONG: return new (C, 4) CMoveLNode( bol, left, right, t->is_long() );
186 case T_OBJECT: return new (C, 4) CMovePNode( c, bol, left, right, t->is_oopptr() );
187 case T_ADDRESS: return new (C, 4) CMovePNode( c, bol, left, right, t->is_ptr() );
188 case T_NARROWOOP: return new (C, 4) CMoveNNode( c, bol, left, right, t );
189 default:
190 ShouldNotReachHere();
191 return NULL;
192 }
193 }
194
195 //=============================================================================
196 //------------------------------Ideal------------------------------------------
197 // Return a node which is more "ideal" than the current node.
198 // Check for conversions to boolean
199 Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
200 // Try generic ideal's first
201 Node *x = CMoveNode::Ideal(phase, can_reshape);
202 if( x ) return x;
203
204 // If zero is on the left (false-case, no-move-case) it must mean another
205 // constant is on the right (otherwise the shared CMove::Ideal code would
206 // have moved the constant to the right). This situation is bad for Intel
207 // and a don't-care for Sparc. It's bad for Intel because the zero has to
208 // be manifested in a register with a XOR which kills flags, which are live
209 // on input to the CMoveI, leading to a situation which causes excessive
210 // spilling on Intel. For Sparc, if the zero in on the left the Sparc will
211 // zero a register via G0 and conditionally-move the other constant. If the
212 // zero is on the right, the Sparc will load the first constant with a
213 // 13-bit set-lo and conditionally move G0. See bug 4677505.
214 if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
215 if( in(Condition)->is_Bool() ) {
216 BoolNode* b = in(Condition)->as_Bool();
217 BoolNode* b2 = b->negate(phase);
218 return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
219 }
220 }
221
222 // Now check for booleans
223 int flip = 0;
224
225 // Check for picking from zero/one
226 if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
227 flip = 1 - flip;
228 } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
229 } else return NULL;
230
231 // Check for eq/ne test
232 if( !in(1)->is_Bool() ) return NULL;
233 BoolNode *bol = in(1)->as_Bool();
234 if( bol->_test._test == BoolTest::eq ) {
235 } else if( bol->_test._test == BoolTest::ne ) {
236 flip = 1-flip;
237 } else return NULL;
238
239 // Check for vs 0 or 1
240 if( !bol->in(1)->is_Cmp() ) return NULL;
241 const CmpNode *cmp = bol->in(1)->as_Cmp();
242 if( phase->type(cmp->in(2)) == TypeInt::ZERO ) {
243 } else if( phase->type(cmp->in(2)) == TypeInt::ONE ) {
244 // Allow cmp-vs-1 if the other input is bounded by 0-1
245 if( phase->type(cmp->in(1)) != TypeInt::BOOL )
246 return NULL;
247 flip = 1 - flip;
248 } else return NULL;
249
250 // Convert to a bool (flipped)
251 // Build int->bool conversion
252 #ifndef PRODUCT
253 if( PrintOpto ) tty->print_cr("CMOV to I2B");
254 #endif
255 Node *n = new (phase->C, 2) Conv2BNode( cmp->in(1) );
256 if( flip )
257 n = new (phase->C, 3) XorINode( phase->transform(n), phase->intcon(1) );
258
259 return n;
260 }
261
262 //=============================================================================
263 //------------------------------Ideal------------------------------------------
264 // Return a node which is more "ideal" than the current node.
265 // Check for absolute value
266 Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
267 // Try generic ideal's first
268 Node *x = CMoveNode::Ideal(phase, can_reshape);
269 if( x ) return x;
270
271 int cmp_zero_idx = 0; // Index of compare input where to look for zero
272 int phi_x_idx = 0; // Index of phi input where to find naked x
273
274 // Find the Bool
275 if( !in(1)->is_Bool() ) return NULL;
276 BoolNode *bol = in(1)->as_Bool();
277 // Check bool sense
278 switch( bol->_test._test ) {
279 case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break;
280 case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
281 case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break;
282 case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
283 default: return NULL; break;
284 }
285
286 // Find zero input of CmpF; the other input is being abs'd
287 Node *cmpf = bol->in(1);
288 if( cmpf->Opcode() != Op_CmpF ) return NULL;
289 Node *X = NULL;
290 bool flip = false;
291 if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
292 X = cmpf->in(3 - cmp_zero_idx);
293 } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
294 // The test is inverted, we should invert the result...
295 X = cmpf->in(cmp_zero_idx);
296 flip = true;
297 } else {
298 return NULL;
299 }
300
301 // If X is found on the appropriate phi input, find the subtract on the other
302 if( X != in(phi_x_idx) ) return NULL;
303 int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
304 Node *sub = in(phi_sub_idx);
305
306 // Allow only SubF(0,X) and fail out for all others; NegF is not OK
307 if( sub->Opcode() != Op_SubF ||
308 sub->in(2) != X ||
309 phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
310
311 Node *abs = new (phase->C, 2) AbsFNode( X );
312 if( flip )
313 abs = new (phase->C, 3) SubFNode(sub->in(1), phase->transform(abs));
314
315 return abs;
316 }
317
318 //=============================================================================
319 //------------------------------Ideal------------------------------------------
320 // Return a node which is more "ideal" than the current node.
321 // Check for absolute value
322 Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
323 // Try generic ideal's first
324 Node *x = CMoveNode::Ideal(phase, can_reshape);
325 if( x ) return x;
326
327 int cmp_zero_idx = 0; // Index of compare input where to look for zero
328 int phi_x_idx = 0; // Index of phi input where to find naked x
329
330 // Find the Bool
331 if( !in(1)->is_Bool() ) return NULL;
332 BoolNode *bol = in(1)->as_Bool();
333 // Check bool sense
334 switch( bol->_test._test ) {
335 case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue; break;
336 case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
337 case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue; break;
338 case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
339 default: return NULL; break;
340 }
341
342 // Find zero input of CmpD; the other input is being abs'd
343 Node *cmpd = bol->in(1);
344 if( cmpd->Opcode() != Op_CmpD ) return NULL;
345 Node *X = NULL;
346 bool flip = false;
347 if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
348 X = cmpd->in(3 - cmp_zero_idx);
349 } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
350 // The test is inverted, we should invert the result...
351 X = cmpd->in(cmp_zero_idx);
352 flip = true;
353 } else {
354 return NULL;
355 }
356
357 // If X is found on the appropriate phi input, find the subtract on the other
358 if( X != in(phi_x_idx) ) return NULL;
359 int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
360 Node *sub = in(phi_sub_idx);
361
362 // Allow only SubD(0,X) and fail out for all others; NegD is not OK
363 if( sub->Opcode() != Op_SubD ||
364 sub->in(2) != X ||
365 phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
366
367 Node *abs = new (phase->C, 2) AbsDNode( X );
368 if( flip )
369 abs = new (phase->C, 3) SubDNode(sub->in(1), phase->transform(abs));
370
371 return abs;
372 }
373
374
375 //=============================================================================
376 // If input is already higher or equal to cast type, then this is an identity.
377 Node *ConstraintCastNode::Identity( PhaseTransform *phase ) {
378 return phase->type(in(1))->higher_equal(_type) ? in(1) : this;
379 }
380
381 //------------------------------Value------------------------------------------
382 // Take 'join' of input and cast-up type
383 const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const {
384 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
385 const Type* ft = phase->type(in(1))->filter(_type);
386
387 #ifdef ASSERT
388 // Previous versions of this function had some special case logic,
389 // which is no longer necessary. Make sure of the required effects.
390 switch (Opcode()) {
391 case Op_CastII:
392 {
393 const Type* t1 = phase->type(in(1));
394 if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1");
395 const Type* rt = t1->join(_type);
396 if (rt->empty()) assert(ft == Type::TOP, "special case #2");
397 break;
398 }
399 case Op_CastPP:
400 if (phase->type(in(1)) == TypePtr::NULL_PTR &&
401 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
402 assert(ft == Type::TOP, "special case #3");
403 break;
404 }
405 #endif //ASSERT
406
407 return ft;
408 }
409
410 //------------------------------Ideal------------------------------------------
411 // Return a node which is more "ideal" than the current node. Strip out
412 // control copies
413 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){
414 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
415 }
416
417 //------------------------------Ideal_DU_postCCP-------------------------------
418 // Throw away cast after constant propagation
419 Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
420 const Type *t = ccp->type(in(1));
421 ccp->hash_delete(this);
422 set_type(t); // Turn into ID function
423 ccp->hash_insert(this);
424 return this;
425 }
426
427
428 //=============================================================================
429
430 //------------------------------Ideal_DU_postCCP-------------------------------
431 // If not converting int->oop, throw away cast after constant propagation
432 Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
433 const Type *t = ccp->type(in(1));
434 if (!t->isa_oop_ptr()) {
435 return NULL; // do not transform raw pointers
436 }
437 return ConstraintCastNode::Ideal_DU_postCCP(ccp);
438 }
439
440
441
442 //=============================================================================
443 //------------------------------Identity---------------------------------------
444 // If input is already higher or equal to cast type, then this is an identity.
445 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
446 // Toned down to rescue meeting at a Phi 3 different oops all implementing
447 // the same interface. CompileTheWorld starting at 502, kd12rc1.zip.
448 return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
449 }
450
451 // Determine whether "n" is a node which can cause an alias of one of its inputs. Node types
452 // which can create aliases are: CheckCastPP, Phi, and any store (if there is also a load from
453 // the location.)
454 // Note: this checks for aliases created in this compilation, not ones which may
455 // be potentially created at call sites.
456 static bool can_cause_alias(Node *n, PhaseTransform *phase) {
457 bool possible_alias = false;
458
459 if (n->is_Store()) {
460 possible_alias = !n->as_Store()->value_never_loaded(phase);
461 } else {
462 int opc = n->Opcode();
463 possible_alias = n->is_Phi() ||
464 opc == Op_CheckCastPP ||
465 opc == Op_StorePConditional ||
466 opc == Op_CompareAndSwapP ||
467 opc == Op_CompareAndSwapN;
468 }
469 return possible_alias;
470 }
471
472 //------------------------------Value------------------------------------------
473 // Take 'join' of input and cast-up type, unless working with an Interface
474 const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
475 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
476
477 const Type *inn = phase->type(in(1));
478 if( inn == Type::TOP ) return Type::TOP; // No information yet
479
480 const TypePtr *in_type = inn->isa_ptr();
481 const TypePtr *my_type = _type->isa_ptr();
482 const Type *result = _type;
483 if( in_type != NULL && my_type != NULL ) {
484 TypePtr::PTR in_ptr = in_type->ptr();
485 if( in_ptr == TypePtr::Null ) {
486 result = in_type;
487 } else if( in_ptr == TypePtr::Constant ) {
488 // Casting a constant oop to an interface?
489 // (i.e., a String to a Comparable?)
490 // Then return the interface.
491 const TypeOopPtr *jptr = my_type->isa_oopptr();
492 assert( jptr, "" );
493 result = (jptr->klass()->is_interface() || !in_type->higher_equal(_type))
494 ? my_type->cast_to_ptr_type( TypePtr::NotNull )
495 : in_type;
496 } else {
497 result = my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
498 }
499 }
500 return result;
501
502 // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
503 // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
504
505 //
506 // Remove this code after overnight run indicates no performance
507 // loss from not performing JOIN at CheckCastPPNode
508 //
509 // const TypeInstPtr *in_oop = in->isa_instptr();
510 // const TypeInstPtr *my_oop = _type->isa_instptr();
511 // // If either input is an 'interface', return destination type
512 // assert (in_oop == NULL || in_oop->klass() != NULL, "");
513 // assert (my_oop == NULL || my_oop->klass() != NULL, "");
514 // if( (in_oop && in_oop->klass()->klass_part()->is_interface())
515 // ||(my_oop && my_oop->klass()->klass_part()->is_interface()) ) {
516 // TypePtr::PTR in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
517 // // Preserve cast away nullness for interfaces
518 // if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
519 // return my_oop->cast_to_ptr_type(TypePtr::NotNull);
520 // }
521 // return _type;
522 // }
523 //
524 // // Neither the input nor the destination type is an interface,
525 //
526 // // history: JOIN used to cause weird corner case bugs
527 // // return (in == TypeOopPtr::NULL_PTR) ? in : _type;
528 // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
529 // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
530 // const Type *join = in->join(_type);
531 // // Check if join preserved NotNull'ness for pointers
532 // if( join->isa_ptr() && _type->isa_ptr() ) {
533 // TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
534 // TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
535 // // If there isn't any NotNull'ness to preserve
536 // // OR if join preserved NotNull'ness then return it
537 // if( type_ptr == TypePtr::BotPTR || type_ptr == TypePtr::Null ||
538 // join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
539 // return join;
540 // }
541 // // ELSE return same old type as before
542 // return _type;
543 // }
544 // // Not joining two pointers
545 // return join;
546 }
547
548 //------------------------------Ideal------------------------------------------
549 // Return a node which is more "ideal" than the current node. Strip out
550 // control copies
551 Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){
552 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
553 }
554
555
556 Node* DecodeNNode::Identity(PhaseTransform* phase) {
557 const Type *t = phase->type( in(1) );
558 if( t == Type::TOP ) return in(1);
559
560 if (in(1)->is_EncodeP()) {
561 // (DecodeN (EncodeP p)) -> p
562 return in(1)->in(1);
563 }
564 return this;
565 }
566
567 const Type *DecodeNNode::Value( PhaseTransform *phase ) const {
568 const Type *t = phase->type( in(1) );
569 if (t == Type::TOP) return Type::TOP;
570 if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR;
571
572 assert(t->isa_narrowoop(), "only narrowoop here");
573 return t->make_ptr();
574 }
575
576 Node* EncodePNode::Identity(PhaseTransform* phase) {
577 const Type *t = phase->type( in(1) );
578 if( t == Type::TOP ) return in(1);
579
580 if (in(1)->is_DecodeN()) {
581 // (EncodeP (DecodeN p)) -> p
582 return in(1)->in(1);
583 }
584 return this;
585 }
586
587 const Type *EncodePNode::Value( PhaseTransform *phase ) const {
588 const Type *t = phase->type( in(1) );
589 if (t == Type::TOP) return Type::TOP;
590 if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR;
591
592 assert(t->isa_oopptr(), "only oopptr here");
593 return t->make_narrowoop();
594 }
595
596
597 Node *EncodePNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
598 return MemNode::Ideal_common_DU_postCCP(ccp, this, in(1));
599 }
600
601 //=============================================================================
602 //------------------------------Identity---------------------------------------
603 Node *Conv2BNode::Identity( PhaseTransform *phase ) {
604 const Type *t = phase->type( in(1) );
605 if( t == Type::TOP ) return in(1);
606 if( t == TypeInt::ZERO ) return in(1);
607 if( t == TypeInt::ONE ) return in(1);
608 if( t == TypeInt::BOOL ) return in(1);
609 return this;
610 }
611
612 //------------------------------Value------------------------------------------
613 const Type *Conv2BNode::Value( PhaseTransform *phase ) const {
614 const Type *t = phase->type( in(1) );
615 if( t == Type::TOP ) return Type::TOP;
616 if( t == TypeInt::ZERO ) return TypeInt::ZERO;
617 if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;
618 const TypePtr *tp = t->isa_ptr();
619 if( tp != NULL ) {
620 if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;
621 if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;
622 if (tp->ptr() == TypePtr::NotNull) return TypeInt::ONE;
623 return TypeInt::BOOL;
624 }
625 if (t->base() != Type::Int) return TypeInt::BOOL;
626 const TypeInt *ti = t->is_int();
627 if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;
628 return TypeInt::BOOL;
629 }
630
631
632 // The conversions operations are all Alpha sorted. Please keep it that way!
633 //=============================================================================
634 //------------------------------Value------------------------------------------
635 const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {
636 const Type *t = phase->type( in(1) );
637 if( t == Type::TOP ) return Type::TOP;
638 if( t == Type::DOUBLE ) return Type::FLOAT;
639 const TypeD *td = t->is_double_constant();
640 return TypeF::make( (float)td->getd() );
641 }
642
643 //------------------------------Identity---------------------------------------
644 // Float's can be converted to doubles with no loss of bits. Hence
645 // converting a float to a double and back to a float is a NOP.
646 Node *ConvD2FNode::Identity(PhaseTransform *phase) {
647 return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;
648 }
649
650 //=============================================================================
651 //------------------------------Value------------------------------------------
652 const Type *ConvD2INode::Value( PhaseTransform *phase ) const {
653 const Type *t = phase->type( in(1) );
654 if( t == Type::TOP ) return Type::TOP;
655 if( t == Type::DOUBLE ) return TypeInt::INT;
656 const TypeD *td = t->is_double_constant();
657 return TypeInt::make( SharedRuntime::d2i( td->getd() ) );
658 }
659
660 //------------------------------Ideal------------------------------------------
661 // If converting to an int type, skip any rounding nodes
662 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
663 if( in(1)->Opcode() == Op_RoundDouble )
664 set_req(1,in(1)->in(1));
665 return NULL;
666 }
667
668 //------------------------------Identity---------------------------------------
669 // Int's can be converted to doubles with no loss of bits. Hence
670 // converting an integer to a double and back to an integer is a NOP.
671 Node *ConvD2INode::Identity(PhaseTransform *phase) {
672 return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;
673 }
674
675 //=============================================================================
676 //------------------------------Value------------------------------------------
677 const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {
678 const Type *t = phase->type( in(1) );
679 if( t == Type::TOP ) return Type::TOP;
680 if( t == Type::DOUBLE ) return TypeLong::LONG;
681 const TypeD *td = t->is_double_constant();
682 return TypeLong::make( SharedRuntime::d2l( td->getd() ) );
683 }
684
685 //------------------------------Identity---------------------------------------
686 Node *ConvD2LNode::Identity(PhaseTransform *phase) {
687 // Remove ConvD2L->ConvL2D->ConvD2L sequences.
688 if( in(1) ->Opcode() == Op_ConvL2D &&
689 in(1)->in(1)->Opcode() == Op_ConvD2L )
690 return in(1)->in(1);
691 return this;
692 }
693
694 //------------------------------Ideal------------------------------------------
695 // If converting to an int type, skip any rounding nodes
696 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
697 if( in(1)->Opcode() == Op_RoundDouble )
698 set_req(1,in(1)->in(1));
699 return NULL;
700 }
701
702 //=============================================================================
703 //------------------------------Value------------------------------------------
704 const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {
705 const Type *t = phase->type( in(1) );
706 if( t == Type::TOP ) return Type::TOP;
707 if( t == Type::FLOAT ) return Type::DOUBLE;
708 const TypeF *tf = t->is_float_constant();
709 #ifndef IA64
710 return TypeD::make( (double)tf->getf() );
711 #else
712 float x = tf->getf();
713 return TypeD::make( (x == 0.0f) ? (double)x : (double)x + ia64_double_zero );
714 #endif
715 }
716
717 //=============================================================================
718 //------------------------------Value------------------------------------------
719 const Type *ConvF2INode::Value( PhaseTransform *phase ) const {
720 const Type *t = phase->type( in(1) );
721 if( t == Type::TOP ) return Type::TOP;
722 if( t == Type::FLOAT ) return TypeInt::INT;
723 const TypeF *tf = t->is_float_constant();
724 return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );
725 }
726
727 //------------------------------Identity---------------------------------------
728 Node *ConvF2INode::Identity(PhaseTransform *phase) {
729 // Remove ConvF2I->ConvI2F->ConvF2I sequences.
730 if( in(1) ->Opcode() == Op_ConvI2F &&
731 in(1)->in(1)->Opcode() == Op_ConvF2I )
732 return in(1)->in(1);
733 return this;
734 }
735
736 //------------------------------Ideal------------------------------------------
737 // If converting to an int type, skip any rounding nodes
738 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
739 if( in(1)->Opcode() == Op_RoundFloat )
740 set_req(1,in(1)->in(1));
741 return NULL;
742 }
743
744 //=============================================================================
745 //------------------------------Value------------------------------------------
746 const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {
747 const Type *t = phase->type( in(1) );
748 if( t == Type::TOP ) return Type::TOP;
749 if( t == Type::FLOAT ) return TypeLong::LONG;
750 const TypeF *tf = t->is_float_constant();
751 return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );
752 }
753
754 //------------------------------Identity---------------------------------------
755 Node *ConvF2LNode::Identity(PhaseTransform *phase) {
756 // Remove ConvF2L->ConvL2F->ConvF2L sequences.
757 if( in(1) ->Opcode() == Op_ConvL2F &&
758 in(1)->in(1)->Opcode() == Op_ConvF2L )
759 return in(1)->in(1);
760 return this;
761 }
762
763 //------------------------------Ideal------------------------------------------
764 // If converting to an int type, skip any rounding nodes
765 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
766 if( in(1)->Opcode() == Op_RoundFloat )
767 set_req(1,in(1)->in(1));
768 return NULL;
769 }
770
771 //=============================================================================
772 //------------------------------Value------------------------------------------
773 const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {
774 const Type *t = phase->type( in(1) );
775 if( t == Type::TOP ) return Type::TOP;
776 const TypeInt *ti = t->is_int();
777 if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );
778 return bottom_type();
779 }
780
781 //=============================================================================
782 //------------------------------Value------------------------------------------
783 const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {
784 const Type *t = phase->type( in(1) );
785 if( t == Type::TOP ) return Type::TOP;
786 const TypeInt *ti = t->is_int();
787 if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );
788 return bottom_type();
789 }
790
791 //------------------------------Identity---------------------------------------
792 Node *ConvI2FNode::Identity(PhaseTransform *phase) {
793 // Remove ConvI2F->ConvF2I->ConvI2F sequences.
794 if( in(1) ->Opcode() == Op_ConvF2I &&
795 in(1)->in(1)->Opcode() == Op_ConvI2F )
796 return in(1)->in(1);
797 return this;
798 }
799
800 //=============================================================================
801 //------------------------------Value------------------------------------------
802 const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {
803 const Type *t = phase->type( in(1) );
804 if( t == Type::TOP ) return Type::TOP;
805 const TypeInt *ti = t->is_int();
806 const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);
807 // Join my declared type against my incoming type.
808 tl = tl->filter(_type);
809 return tl;
810 }
811
812 #ifdef _LP64
813 static inline bool long_ranges_overlap(jlong lo1, jlong hi1,
814 jlong lo2, jlong hi2) {
815 // Two ranges overlap iff one range's low point falls in the other range.
816 return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);
817 }
818 #endif
819
820 //------------------------------Ideal------------------------------------------
821 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
822 const TypeLong* this_type = this->type()->is_long();
823 Node* this_changed = NULL;
824
825 // If _major_progress, then more loop optimizations follow. Do NOT
826 // remove this node's type assertion until no more loop ops can happen.
827 // The progress bit is set in the major loop optimizations THEN comes the
828 // call to IterGVN and any chance of hitting this code. Cf. Opaque1Node.
829 if (can_reshape && !phase->C->major_progress()) {
830 const TypeInt* in_type = phase->type(in(1))->isa_int();
831 if (in_type != NULL && this_type != NULL &&
832 (in_type->_lo != this_type->_lo ||
833 in_type->_hi != this_type->_hi)) {
834 // Although this WORSENS the type, it increases GVN opportunities,
835 // because I2L nodes with the same input will common up, regardless
836 // of slightly differing type assertions. Such slight differences
837 // arise routinely as a result of loop unrolling, so this is a
838 // post-unrolling graph cleanup. Choose a type which depends only
839 // on my input. (Exception: Keep a range assertion of >=0 or <0.)
840 jlong lo1 = this_type->_lo;
841 jlong hi1 = this_type->_hi;
842 int w1 = this_type->_widen;
843 if (lo1 != (jint)lo1 ||
844 hi1 != (jint)hi1 ||
845 lo1 > hi1) {
846 // Overflow leads to wraparound, wraparound leads to range saturation.
847 lo1 = min_jint; hi1 = max_jint;
848 } else if (lo1 >= 0) {
849 // Keep a range assertion of >=0.
850 lo1 = 0; hi1 = max_jint;
851 } else if (hi1 < 0) {
852 // Keep a range assertion of <0.
853 lo1 = min_jint; hi1 = -1;
854 } else {
855 lo1 = min_jint; hi1 = max_jint;
856 }
857 const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
858 MIN2((jlong)in_type->_hi, hi1),
859 MAX2((int)in_type->_widen, w1));
860 if (wtype != type()) {
861 set_type(wtype);
862 // Note: this_type still has old type value, for the logic below.
863 this_changed = this;
864 }
865 }
866 }
867
868 #ifdef _LP64
869 // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) ,
870 // but only if x and y have subranges that cannot cause 32-bit overflow,
871 // under the assumption that x+y is in my own subrange this->type().
872
873 // This assumption is based on a constraint (i.e., type assertion)
874 // established in Parse::array_addressing or perhaps elsewhere.
875 // This constraint has been adjoined to the "natural" type of
876 // the incoming argument in(0). We know (because of runtime
877 // checks) - that the result value I2L(x+y) is in the joined range.
878 // Hence we can restrict the incoming terms (x, y) to values such
879 // that their sum also lands in that range.
880
881 // This optimization is useful only on 64-bit systems, where we hope
882 // the addition will end up subsumed in an addressing mode.
883 // It is necessary to do this when optimizing an unrolled array
884 // copy loop such as x[i++] = y[i++].
885
886 // On 32-bit systems, it's better to perform as much 32-bit math as
887 // possible before the I2L conversion, because 32-bit math is cheaper.
888 // There's no common reason to "leak" a constant offset through the I2L.
889 // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
890
891 Node* z = in(1);
892 int op = z->Opcode();
893 if (op == Op_AddI || op == Op_SubI) {
894 Node* x = z->in(1);
895 Node* y = z->in(2);
896 assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
897 if (phase->type(x) == Type::TOP) return this_changed;
898 if (phase->type(y) == Type::TOP) return this_changed;
899 const TypeInt* tx = phase->type(x)->is_int();
900 const TypeInt* ty = phase->type(y)->is_int();
901 const TypeLong* tz = this_type;
902 jlong xlo = tx->_lo;
903 jlong xhi = tx->_hi;
904 jlong ylo = ty->_lo;
905 jlong yhi = ty->_hi;
906 jlong zlo = tz->_lo;
907 jlong zhi = tz->_hi;
908 jlong vbit = CONST64(1) << BitsPerInt;
909 int widen = MAX2(tx->_widen, ty->_widen);
910 if (op == Op_SubI) {
911 jlong ylo0 = ylo;
912 ylo = -yhi;
913 yhi = -ylo0;
914 }
915 // See if x+y can cause positive overflow into z+2**32
916 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {
917 return this_changed;
918 }
919 // See if x+y can cause negative overflow into z-2**32
920 if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {
921 return this_changed;
922 }
923 // Now it's always safe to assume x+y does not overflow.
924 // This is true even if some pairs x,y might cause overflow, as long
925 // as that overflow value cannot fall into [zlo,zhi].
926
927 // Confident that the arithmetic is "as if infinite precision",
928 // we can now use z's range to put constraints on those of x and y.
929 // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a
930 // more "restricted" range by intersecting [xlo,xhi] with the
931 // range obtained by subtracting y's range from the asserted range
932 // of the I2L conversion. Here's the interval arithmetic algebra:
933 // x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
934 // => x in [zlo-yhi, zhi-ylo]
935 // => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
936 // => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
937 jlong rxlo = MAX2(xlo, zlo - yhi);
938 jlong rxhi = MIN2(xhi, zhi - ylo);
939 // And similarly, x changing place with y:
940 jlong rylo = MAX2(ylo, zlo - xhi);
941 jlong ryhi = MIN2(yhi, zhi - xlo);
942 if (rxlo > rxhi || rylo > ryhi) {
943 return this_changed; // x or y is dying; don't mess w/ it
944 }
945 if (op == Op_SubI) {
946 jlong rylo0 = rylo;
947 rylo = -ryhi;
948 ryhi = -rylo0;
949 }
950
951 Node* cx = phase->transform( new (phase->C, 2) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) );
952 Node* cy = phase->transform( new (phase->C, 2) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) );
953 switch (op) {
954 case Op_AddI: return new (phase->C, 3) AddLNode(cx, cy);
955 case Op_SubI: return new (phase->C, 3) SubLNode(cx, cy);
956 default: ShouldNotReachHere();
957 }
958 }
959 #endif //_LP64
960
961 return this_changed;
962 }
963
964 //=============================================================================
965 //------------------------------Value------------------------------------------
966 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
967 const Type *t = phase->type( in(1) );
968 if( t == Type::TOP ) return Type::TOP;
969 const TypeLong *tl = t->is_long();
970 if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
971 return bottom_type();
972 }
973
974 //=============================================================================
975 //------------------------------Value------------------------------------------
976 const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {
977 const Type *t = phase->type( in(1) );
978 if( t == Type::TOP ) return Type::TOP;
979 const TypeLong *tl = t->is_long();
980 if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );
981 return bottom_type();
982 }
983
984 //=============================================================================
985 //----------------------------Identity-----------------------------------------
986 Node *ConvL2INode::Identity( PhaseTransform *phase ) {
987 // Convert L2I(I2L(x)) => x
988 if (in(1)->Opcode() == Op_ConvI2L) return in(1)->in(1);
989 return this;
990 }
991
992 //------------------------------Value------------------------------------------
993 const Type *ConvL2INode::Value( PhaseTransform *phase ) const {
994 const Type *t = phase->type( in(1) );
995 if( t == Type::TOP ) return Type::TOP;
996 const TypeLong *tl = t->is_long();
997 if (tl->is_con())
998 // Easy case.
999 return TypeInt::make((jint)tl->get_con());
1000 return bottom_type();
1001 }
1002
1003 //------------------------------Ideal------------------------------------------
1004 // Return a node which is more "ideal" than the current node.
1005 // Blow off prior masking to int
1006 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
1007 Node *andl = in(1);
1008 uint andl_op = andl->Opcode();
1009 if( andl_op == Op_AndL ) {
1010 // Blow off prior masking to int
1011 if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {
1012 set_req(1,andl->in(1));
1013 return this;
1014 }
1015 }
1016
1017 // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
1018 // This replaces an 'AddL' with an 'AddI'.
1019 if( andl_op == Op_AddL ) {
1020 // Don't do this for nodes which have more than one user since
1021 // we'll end up computing the long add anyway.
1022 if (andl->outcnt() > 1) return NULL;
1023
1024 Node* x = andl->in(1);
1025 Node* y = andl->in(2);
1026 assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );
1027 if (phase->type(x) == Type::TOP) return NULL;
1028 if (phase->type(y) == Type::TOP) return NULL;
1029 Node *add1 = phase->transform(new (phase->C, 2) ConvL2INode(x));
1030 Node *add2 = phase->transform(new (phase->C, 2) ConvL2INode(y));
1031 return new (phase->C, 3) AddINode(add1,add2);
1032 }
1033
1034 // Disable optimization: LoadL->ConvL2I ==> LoadI.
1035 // It causes problems (sizes of Load and Store nodes do not match)
1036 // in objects initialization code and Escape Analysis.
1037 return NULL;
1038 }
1039
1040 //=============================================================================
1041 //------------------------------Value------------------------------------------
1042 const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
1043 const Type* t = phase->type(in(1));
1044 if (t->base() == Type_X && t->singleton()) {
1045 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
1046 if (bits == 0) return TypePtr::NULL_PTR;
1047 return TypeRawPtr::make((address) bits);
1048 }
1049 return CastX2PNode::bottom_type();
1050 }
1051
1052 //------------------------------Idealize---------------------------------------
1053 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
1054 if (t == Type::TOP) return false;
1055 const TypeX* tl = t->is_intptr_t();
1056 jint lo = min_jint;
1057 jint hi = max_jint;
1058 if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow
1059 return (tl->_lo >= lo) && (tl->_hi <= hi);
1060 }
1061
1062 static inline Node* addP_of_X2P(PhaseGVN *phase,
1063 Node* base,
1064 Node* dispX,
1065 bool negate = false) {
1066 if (negate) {
1067 dispX = new (phase->C, 3) SubXNode(phase->MakeConX(0), phase->transform(dispX));
1068 }
1069 return new (phase->C, 4) AddPNode(phase->C->top(),
1070 phase->transform(new (phase->C, 2) CastX2PNode(base)),
1071 phase->transform(dispX));
1072 }
1073
1074 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1075 // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
1076 int op = in(1)->Opcode();
1077 Node* x;
1078 Node* y;
1079 switch (op) {
1080 case Op_SubX:
1081 x = in(1)->in(1);
1082 y = in(1)->in(2);
1083 if (fits_in_int(phase->type(y), true)) {
1084 return addP_of_X2P(phase, x, y, true);
1085 }
1086 break;
1087 case Op_AddX:
1088 x = in(1)->in(1);
1089 y = in(1)->in(2);
1090 if (fits_in_int(phase->type(y))) {
1091 return addP_of_X2P(phase, x, y);
1092 }
1093 if (fits_in_int(phase->type(x))) {
1094 return addP_of_X2P(phase, y, x);
1095 }
1096 break;
1097 }
1098 return NULL;
1099 }
1100
1101 //------------------------------Identity---------------------------------------
1102 Node *CastX2PNode::Identity( PhaseTransform *phase ) {
1103 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
1104 return this;
1105 }
1106
1107 //=============================================================================
1108 //------------------------------Value------------------------------------------
1109 const Type *CastP2XNode::Value( PhaseTransform *phase ) const {
1110 const Type* t = phase->type(in(1));
1111 if (t->base() == Type::RawPtr && t->singleton()) {
1112 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
1113 return TypeX::make(bits);
1114 }
1115 return CastP2XNode::bottom_type();
1116 }
1117
1118 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1119 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
1120 }
1121
1122 //------------------------------Identity---------------------------------------
1123 Node *CastP2XNode::Identity( PhaseTransform *phase ) {
1124 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
1125 return this;
1126 }
1127
1128
1129 //=============================================================================
1130 //------------------------------Identity---------------------------------------
1131 // Remove redundant roundings
1132 Node *RoundFloatNode::Identity( PhaseTransform *phase ) {
1133 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
1134 // Do not round constants
1135 if (phase->type(in(1))->base() == Type::FloatCon) return in(1);
1136 int op = in(1)->Opcode();
1137 // Redundant rounding
1138 if( op == Op_RoundFloat ) return in(1);
1139 // Already rounded
1140 if( op == Op_Parm ) return in(1);
1141 if( op == Op_LoadF ) return in(1);
1142 return this;
1143 }
1144
1145 //------------------------------Value------------------------------------------
1146 const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {
1147 return phase->type( in(1) );
1148 }
1149
1150 //=============================================================================
1151 //------------------------------Identity---------------------------------------
1152 // Remove redundant roundings. Incoming arguments are already rounded.
1153 Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {
1154 assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
1155 // Do not round constants
1156 if (phase->type(in(1))->base() == Type::DoubleCon) return in(1);
1157 int op = in(1)->Opcode();
1158 // Redundant rounding
1159 if( op == Op_RoundDouble ) return in(1);
1160 // Already rounded
1161 if( op == Op_Parm ) return in(1);
1162 if( op == Op_LoadD ) return in(1);
1163 if( op == Op_ConvF2D ) return in(1);
1164 if( op == Op_ConvI2D ) return in(1);
1165 return this;
1166 }
1167
1168 //------------------------------Value------------------------------------------
1169 const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {
1170 return phase->type( in(1) );
1171 }
1172
1173
1174 //=============================================================================
1175 // Do not allow value-numbering
1176 uint Opaque1Node::hash() const { return NO_HASH; }
1177 uint Opaque1Node::cmp( const Node &n ) const {
1178 return (&n == this); // Always fail except on self
1179 }
1180
1181 //------------------------------Identity---------------------------------------
1182 // If _major_progress, then more loop optimizations follow. Do NOT remove
1183 // the opaque Node until no more loop ops can happen. Note the timing of
1184 // _major_progress; it's set in the major loop optimizations THEN comes the
1185 // call to IterGVN and any chance of hitting this code. Hence there's no
1186 // phase-ordering problem with stripping Opaque1 in IGVN followed by some
1187 // more loop optimizations that require it.
1188 Node *Opaque1Node::Identity( PhaseTransform *phase ) {
1189 return phase->C->major_progress() ? this : in(1);
1190 }
1191
1192 //=============================================================================
1193 // A node to prevent unwanted optimizations. Allows constant folding. Stops
1194 // value-numbering, most Ideal calls or Identity functions. This Node is
1195 // specifically designed to prevent the pre-increment value of a loop trip
1196 // counter from being live out of the bottom of the loop (hence causing the
1197 // pre- and post-increment values both being live and thus requiring an extra
1198 // temp register and an extra move). If we "accidentally" optimize through
1199 // this kind of a Node, we'll get slightly pessimal, but correct, code. Thus
1200 // it's OK to be slightly sloppy on optimizations here.
1201
1202 // Do not allow value-numbering
1203 uint Opaque2Node::hash() const { return NO_HASH; }
1204 uint Opaque2Node::cmp( const Node &n ) const {
1205 return (&n == this); // Always fail except on self
1206 }
1207
1208
1209 //------------------------------Value------------------------------------------
1210 const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {
1211 const Type *t = phase->type( in(1) );
1212 if( t == Type::TOP ) return Type::TOP;
1213 const TypeLong *tl = t->is_long();
1214 if( !tl->is_con() ) return bottom_type();
1215 JavaValue v;
1216 v.set_jlong(tl->get_con());
1217 return TypeD::make( v.get_jdouble() );
1218 }
1219
1220 //------------------------------Value------------------------------------------
1221 const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {
1222 const Type *t = phase->type( in(1) );
1223 if( t == Type::TOP ) return Type::TOP;
1224 const TypeInt *ti = t->is_int();
1225 if( !ti->is_con() ) return bottom_type();
1226 JavaValue v;
1227 v.set_jint(ti->get_con());
1228 return TypeF::make( v.get_jfloat() );
1229 }
1230
1231 //------------------------------Value------------------------------------------
1232 const Type *MoveF2INode::Value( PhaseTransform *phase ) const {
1233 const Type *t = phase->type( in(1) );
1234 if( t == Type::TOP ) return Type::TOP;
1235 if( t == Type::FLOAT ) return TypeInt::INT;
1236 const TypeF *tf = t->is_float_constant();
1237 JavaValue v;
1238 v.set_jfloat(tf->getf());
1239 return TypeInt::make( v.get_jint() );
1240 }
1241
1242 //------------------------------Value------------------------------------------
1243 const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {
1244 const Type *t = phase->type( in(1) );
1245 if( t == Type::TOP ) return Type::TOP;
1246 if( t == Type::DOUBLE ) return TypeLong::LONG;
1247 const TypeD *td = t->is_double_constant();
1248 JavaValue v;
1249 v.set_jdouble(td->getd());
1250 return TypeLong::make( v.get_jlong() );
1251 }