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