src/share/vm/opto/connode.cpp

Mon, 28 Apr 2008 08:08:12 -0700

author
rasbold
date
Mon, 28 Apr 2008 08:08:12 -0700
changeset 563
a76240c8b133
parent 559
b130b98db9cf
child 598
885ed790ecf0
permissions
-rw-r--r--

Merge

     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  */
    25 // Optimization - Graph Style
    27 #include "incls/_precompiled.incl"
    28 #include "incls/_connode.cpp.incl"
    30 //=============================================================================
    31 //------------------------------hash-------------------------------------------
    32 uint ConNode::hash() const {
    33   return (uintptr_t)in(TypeFunc::Control) + _type->hash();
    34 }
    36 //------------------------------make-------------------------------------------
    37 ConNode *ConNode::make( Compile* C, const Type *t ) {
    38   if (t->isa_narrowoop()) return new (C, 1) ConNNode( t->is_narrowoop() );
    39   switch( t->basic_type() ) {
    40   case T_INT:       return new (C, 1) ConINode( t->is_int() );
    41   case T_ARRAY:     return new (C, 1) ConPNode( t->is_aryptr() );
    42   case T_LONG:      return new (C, 1) ConLNode( t->is_long() );
    43   case T_FLOAT:     return new (C, 1) ConFNode( t->is_float_constant() );
    44   case T_DOUBLE:    return new (C, 1) ConDNode( t->is_double_constant() );
    45   case T_VOID:      return new (C, 1) ConNode ( Type::TOP );
    46   case T_OBJECT:    return new (C, 1) ConPNode( t->is_oopptr() );
    47   case T_ADDRESS:   return new (C, 1) ConPNode( t->is_ptr() );
    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 }
    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:
    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.
    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.
    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.
    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.
    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).
    96 */
    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
   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 }
   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 }
   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
   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   }
   166   return this;
   167 }
   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 }
   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   default:
   189     ShouldNotReachHere();
   190     return NULL;
   191   }
   192 }
   194 //=============================================================================
   195 //------------------------------Ideal------------------------------------------
   196 // Return a node which is more "ideal" than the current node.
   197 // Check for conversions to boolean
   198 Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
   199   // Try generic ideal's first
   200   Node *x = CMoveNode::Ideal(phase, can_reshape);
   201   if( x ) return x;
   203   // If zero is on the left (false-case, no-move-case) it must mean another
   204   // constant is on the right (otherwise the shared CMove::Ideal code would
   205   // have moved the constant to the right).  This situation is bad for Intel
   206   // and a don't-care for Sparc.  It's bad for Intel because the zero has to
   207   // be manifested in a register with a XOR which kills flags, which are live
   208   // on input to the CMoveI, leading to a situation which causes excessive
   209   // spilling on Intel.  For Sparc, if the zero in on the left the Sparc will
   210   // zero a register via G0 and conditionally-move the other constant.  If the
   211   // zero is on the right, the Sparc will load the first constant with a
   212   // 13-bit set-lo and conditionally move G0.  See bug 4677505.
   213   if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
   214     if( in(Condition)->is_Bool() ) {
   215       BoolNode* b  = in(Condition)->as_Bool();
   216       BoolNode* b2 = b->negate(phase);
   217       return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
   218     }
   219   }
   221   // Now check for booleans
   222   int flip = 0;
   224   // Check for picking from zero/one
   225   if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
   226     flip = 1 - flip;
   227   } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
   228   } else return NULL;
   230   // Check for eq/ne test
   231   if( !in(1)->is_Bool() ) return NULL;
   232   BoolNode *bol = in(1)->as_Bool();
   233   if( bol->_test._test == BoolTest::eq ) {
   234   } else if( bol->_test._test == BoolTest::ne ) {
   235     flip = 1-flip;
   236   } else return NULL;
   238   // Check for vs 0 or 1
   239   if( !bol->in(1)->is_Cmp() ) return NULL;
   240   const CmpNode *cmp = bol->in(1)->as_Cmp();
   241   if( phase->type(cmp->in(2)) == TypeInt::ZERO ) {
   242   } else if( phase->type(cmp->in(2)) == TypeInt::ONE ) {
   243     // Allow cmp-vs-1 if the other input is bounded by 0-1
   244     if( phase->type(cmp->in(1)) != TypeInt::BOOL )
   245       return NULL;
   246     flip = 1 - flip;
   247   } else return NULL;
   249   // Convert to a bool (flipped)
   250   // Build int->bool conversion
   251 #ifndef PRODUCT
   252   if( PrintOpto ) tty->print_cr("CMOV to I2B");
   253 #endif
   254   Node *n = new (phase->C, 2) Conv2BNode( cmp->in(1) );
   255   if( flip )
   256     n = new (phase->C, 3) XorINode( phase->transform(n), phase->intcon(1) );
   258   return n;
   259 }
   261 //=============================================================================
   262 //------------------------------Ideal------------------------------------------
   263 // Return a node which is more "ideal" than the current node.
   264 // Check for absolute value
   265 Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   266   // Try generic ideal's first
   267   Node *x = CMoveNode::Ideal(phase, can_reshape);
   268   if( x ) return x;
   270   int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
   271   int  phi_x_idx = 0;           // Index of phi input where to find naked x
   273   // Find the Bool
   274   if( !in(1)->is_Bool() ) return NULL;
   275   BoolNode *bol = in(1)->as_Bool();
   276   // Check bool sense
   277   switch( bol->_test._test ) {
   278   case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
   279   case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
   280   case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
   281   case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
   282   default:           return NULL;                           break;
   283   }
   285   // Find zero input of CmpF; the other input is being abs'd
   286   Node *cmpf = bol->in(1);
   287   if( cmpf->Opcode() != Op_CmpF ) return NULL;
   288   Node *X = NULL;
   289   bool flip = false;
   290   if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
   291     X = cmpf->in(3 - cmp_zero_idx);
   292   } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
   293     // The test is inverted, we should invert the result...
   294     X = cmpf->in(cmp_zero_idx);
   295     flip = true;
   296   } else {
   297     return NULL;
   298   }
   300   // If X is found on the appropriate phi input, find the subtract on the other
   301   if( X != in(phi_x_idx) ) return NULL;
   302   int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
   303   Node *sub = in(phi_sub_idx);
   305   // Allow only SubF(0,X) and fail out for all others; NegF is not OK
   306   if( sub->Opcode() != Op_SubF ||
   307       sub->in(2) != X ||
   308       phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
   310   Node *abs = new (phase->C, 2) AbsFNode( X );
   311   if( flip )
   312     abs = new (phase->C, 3) SubFNode(sub->in(1), phase->transform(abs));
   314   return abs;
   315 }
   317 //=============================================================================
   318 //------------------------------Ideal------------------------------------------
   319 // Return a node which is more "ideal" than the current node.
   320 // Check for absolute value
   321 Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   322   // Try generic ideal's first
   323   Node *x = CMoveNode::Ideal(phase, can_reshape);
   324   if( x ) return x;
   326   int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
   327   int  phi_x_idx = 0;           // Index of phi input where to find naked x
   329   // Find the Bool
   330   if( !in(1)->is_Bool() ) return NULL;
   331   BoolNode *bol = in(1)->as_Bool();
   332   // Check bool sense
   333   switch( bol->_test._test ) {
   334   case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
   335   case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
   336   case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
   337   case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
   338   default:           return NULL;                           break;
   339   }
   341   // Find zero input of CmpD; the other input is being abs'd
   342   Node *cmpd = bol->in(1);
   343   if( cmpd->Opcode() != Op_CmpD ) return NULL;
   344   Node *X = NULL;
   345   bool flip = false;
   346   if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
   347     X = cmpd->in(3 - cmp_zero_idx);
   348   } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
   349     // The test is inverted, we should invert the result...
   350     X = cmpd->in(cmp_zero_idx);
   351     flip = true;
   352   } else {
   353     return NULL;
   354   }
   356   // If X is found on the appropriate phi input, find the subtract on the other
   357   if( X != in(phi_x_idx) ) return NULL;
   358   int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
   359   Node *sub = in(phi_sub_idx);
   361   // Allow only SubD(0,X) and fail out for all others; NegD is not OK
   362   if( sub->Opcode() != Op_SubD ||
   363       sub->in(2) != X ||
   364       phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
   366   Node *abs = new (phase->C, 2) AbsDNode( X );
   367   if( flip )
   368     abs = new (phase->C, 3) SubDNode(sub->in(1), phase->transform(abs));
   370   return abs;
   371 }
   374 //=============================================================================
   375 // If input is already higher or equal to cast type, then this is an identity.
   376 Node *ConstraintCastNode::Identity( PhaseTransform *phase ) {
   377   return phase->type(in(1))->higher_equal(_type) ? in(1) : this;
   378 }
   380 //------------------------------Value------------------------------------------
   381 // Take 'join' of input and cast-up type
   382 const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const {
   383   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
   384   const Type* ft = phase->type(in(1))->filter(_type);
   386 #ifdef ASSERT
   387   // Previous versions of this function had some special case logic,
   388   // which is no longer necessary.  Make sure of the required effects.
   389   switch (Opcode()) {
   390   case Op_CastII:
   391     {
   392       const Type* t1 = phase->type(in(1));
   393       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
   394       const Type* rt = t1->join(_type);
   395       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
   396       break;
   397     }
   398   case Op_CastPP:
   399     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
   400         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
   401       assert(ft == Type::TOP, "special case #3");
   402     break;
   403   }
   404 #endif //ASSERT
   406   return ft;
   407 }
   409 //------------------------------Ideal------------------------------------------
   410 // Return a node which is more "ideal" than the current node.  Strip out
   411 // control copies
   412 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){
   413   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
   414 }
   416 //------------------------------Ideal_DU_postCCP-------------------------------
   417 // Throw away cast after constant propagation
   418 Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
   419   const Type *t = ccp->type(in(1));
   420   ccp->hash_delete(this);
   421   set_type(t);                   // Turn into ID function
   422   ccp->hash_insert(this);
   423   return this;
   424 }
   427 //=============================================================================
   429 //------------------------------Ideal_DU_postCCP-------------------------------
   430 // If not converting int->oop, throw away cast after constant propagation
   431 Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
   432   const Type *t = ccp->type(in(1));
   433   if (!t->isa_oop_ptr()) {
   434     return NULL;                // do not transform raw pointers
   435   }
   436   return ConstraintCastNode::Ideal_DU_postCCP(ccp);
   437 }
   441 //=============================================================================
   442 //------------------------------Identity---------------------------------------
   443 // If input is already higher or equal to cast type, then this is an identity.
   444 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
   445   // Toned down to rescue meeting at a Phi 3 different oops all implementing
   446   // the same interface.  CompileTheWorld starting at 502, kd12rc1.zip.
   447   return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
   448 }
   450 // Determine whether "n" is a node which can cause an alias of one of its inputs.  Node types
   451 // which can create aliases are: CheckCastPP, Phi, and any store (if there is also a load from
   452 // the location.)
   453 // Note:  this checks for aliases created in this compilation, not ones which may
   454 //        be potentially created at call sites.
   455 static bool can_cause_alias(Node *n, PhaseTransform *phase) {
   456   bool possible_alias = false;
   458   if (n->is_Store()) {
   459     possible_alias = !n->as_Store()->value_never_loaded(phase);
   460   } else {
   461     int opc = n->Opcode();
   462     possible_alias = n->is_Phi() ||
   463         opc == Op_CheckCastPP ||
   464         opc == Op_StorePConditional ||
   465         opc == Op_CompareAndSwapP ||
   466         opc == Op_CompareAndSwapN;
   467   }
   468   return possible_alias;
   469 }
   471 //------------------------------Value------------------------------------------
   472 // Take 'join' of input and cast-up type, unless working with an Interface
   473 const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
   474   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
   476   const Type *inn = phase->type(in(1));
   477   if( inn == Type::TOP ) return Type::TOP;  // No information yet
   479   const TypePtr *in_type   = inn->isa_ptr();
   480   const TypePtr *my_type   = _type->isa_ptr();
   481   const Type *result = _type;
   482   if( in_type != NULL && my_type != NULL ) {
   483     TypePtr::PTR   in_ptr    = in_type->ptr();
   484     if( in_ptr == TypePtr::Null ) {
   485       result = in_type;
   486     } else if( in_ptr == TypePtr::Constant ) {
   487       // Casting a constant oop to an interface?
   488       // (i.e., a String to a Comparable?)
   489       // Then return the interface.
   490       const TypeOopPtr *jptr = my_type->isa_oopptr();
   491       assert( jptr, "" );
   492       result =  (jptr->klass()->is_interface() || !in_type->higher_equal(_type))
   493         ? my_type->cast_to_ptr_type( TypePtr::NotNull )
   494         : in_type;
   495     } else {
   496       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
   497     }
   498   }
   499   return result;
   501   // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
   502   // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
   504   //
   505   // Remove this code after overnight run indicates no performance
   506   // loss from not performing JOIN at CheckCastPPNode
   507   //
   508   // const TypeInstPtr *in_oop = in->isa_instptr();
   509   // const TypeInstPtr *my_oop = _type->isa_instptr();
   510   // // If either input is an 'interface', return destination type
   511   // assert (in_oop == NULL || in_oop->klass() != NULL, "");
   512   // assert (my_oop == NULL || my_oop->klass() != NULL, "");
   513   // if( (in_oop && in_oop->klass()->klass_part()->is_interface())
   514   //   ||(my_oop && my_oop->klass()->klass_part()->is_interface()) ) {
   515   //   TypePtr::PTR  in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
   516   //   // Preserve cast away nullness for interfaces
   517   //   if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
   518   //     return my_oop->cast_to_ptr_type(TypePtr::NotNull);
   519   //   }
   520   //   return _type;
   521   // }
   522   //
   523   // // Neither the input nor the destination type is an interface,
   524   //
   525   // // history: JOIN used to cause weird corner case bugs
   526   // //          return (in == TypeOopPtr::NULL_PTR) ? in : _type;
   527   // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
   528   // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
   529   // const Type *join = in->join(_type);
   530   // // Check if join preserved NotNull'ness for pointers
   531   // if( join->isa_ptr() && _type->isa_ptr() ) {
   532   //   TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
   533   //   TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
   534   //   // If there isn't any NotNull'ness to preserve
   535   //   // OR if join preserved NotNull'ness then return it
   536   //   if( type_ptr == TypePtr::BotPTR  || type_ptr == TypePtr::Null ||
   537   //       join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
   538   //     return join;
   539   //   }
   540   //   // ELSE return same old type as before
   541   //   return _type;
   542   // }
   543   // // Not joining two pointers
   544   // return join;
   545 }
   547 //------------------------------Ideal------------------------------------------
   548 // Return a node which is more "ideal" than the current node.  Strip out
   549 // control copies
   550 Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){
   551   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
   552 }
   555 Node* DecodeNNode::Identity(PhaseTransform* phase) {
   556   const Type *t = phase->type( in(1) );
   557   if( t == Type::TOP ) return in(1);
   559   if (in(1)->Opcode() == Op_EncodeP) {
   560     // (DecodeN (EncodeP p)) -> p
   561     return in(1)->in(1);
   562   }
   563   return this;
   564 }
   566 const Type *DecodeNNode::Value( PhaseTransform *phase ) const {
   567   if (phase->type( in(1) ) == TypeNarrowOop::NULL_PTR) {
   568     return TypePtr::NULL_PTR;
   569   }
   570   return bottom_type();
   571 }
   573 Node* DecodeNNode::decode(PhaseGVN* phase, Node* value) {
   574   if (value->Opcode() == Op_EncodeP) {
   575     // (DecodeN (EncodeP p)) -> p
   576     return value->in(1);
   577   }
   578   const Type* newtype = value->bottom_type();
   579   if (newtype == TypeNarrowOop::NULL_PTR) {
   580     return phase->transform(new (phase->C, 1) ConPNode(TypePtr::NULL_PTR));
   581   } else {
   582     return phase->transform(new (phase->C, 2) DecodeNNode(value, newtype->is_narrowoop()->make_oopptr()));
   583   }
   584 }
   586 Node* EncodePNode::Identity(PhaseTransform* phase) {
   587   const Type *t = phase->type( in(1) );
   588   if( t == Type::TOP ) return in(1);
   590   if (in(1)->Opcode() == Op_DecodeN) {
   591     // (EncodeP (DecodeN p)) -> p
   592     return in(1)->in(1);
   593   }
   594   return this;
   595 }
   597 const Type *EncodePNode::Value( PhaseTransform *phase ) const {
   598   if (phase->type( in(1) ) == TypePtr::NULL_PTR) {
   599     return TypeNarrowOop::NULL_PTR;
   600   }
   601   return bottom_type();
   602 }
   604 Node* EncodePNode::encode(PhaseGVN* phase, Node* value) {
   605   if (value->Opcode() == Op_DecodeN) {
   606     // (EncodeP (DecodeN p)) -> p
   607     return value->in(1);
   608   }
   609   const Type* newtype = value->bottom_type();
   610   if (newtype == TypePtr::NULL_PTR) {
   611     return phase->transform(new (phase->C, 1) ConNNode(TypeNarrowOop::NULL_PTR));
   612   } else if (newtype->isa_oopptr()) {
   613     return phase->transform(new (phase->C, 2) EncodePNode(value, newtype->is_oopptr()->make_narrowoop()));
   614   } else {
   615     ShouldNotReachHere();
   616     return NULL; // to make C++ compiler happy.
   617   }
   618 }
   621 //=============================================================================
   622 //------------------------------Identity---------------------------------------
   623 Node *Conv2BNode::Identity( PhaseTransform *phase ) {
   624   const Type *t = phase->type( in(1) );
   625   if( t == Type::TOP ) return in(1);
   626   if( t == TypeInt::ZERO ) return in(1);
   627   if( t == TypeInt::ONE ) return in(1);
   628   if( t == TypeInt::BOOL ) return in(1);
   629   return this;
   630 }
   632 //------------------------------Value------------------------------------------
   633 const Type *Conv2BNode::Value( PhaseTransform *phase ) const {
   634   const Type *t = phase->type( in(1) );
   635   if( t == Type::TOP ) return Type::TOP;
   636   if( t == TypeInt::ZERO ) return TypeInt::ZERO;
   637   if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;
   638   const TypePtr *tp = t->isa_ptr();
   639   if( tp != NULL ) {
   640     if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;
   641     if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;
   642     if (tp->ptr() == TypePtr::NotNull)  return TypeInt::ONE;
   643     return TypeInt::BOOL;
   644   }
   645   if (t->base() != Type::Int) return TypeInt::BOOL;
   646   const TypeInt *ti = t->is_int();
   647   if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;
   648   return TypeInt::BOOL;
   649 }
   652 // The conversions operations are all Alpha sorted.  Please keep it that way!
   653 //=============================================================================
   654 //------------------------------Value------------------------------------------
   655 const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {
   656   const Type *t = phase->type( in(1) );
   657   if( t == Type::TOP ) return Type::TOP;
   658   if( t == Type::DOUBLE ) return Type::FLOAT;
   659   const TypeD *td = t->is_double_constant();
   660   return TypeF::make( (float)td->getd() );
   661 }
   663 //------------------------------Identity---------------------------------------
   664 // Float's can be converted to doubles with no loss of bits.  Hence
   665 // converting a float to a double and back to a float is a NOP.
   666 Node *ConvD2FNode::Identity(PhaseTransform *phase) {
   667   return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;
   668 }
   670 //=============================================================================
   671 //------------------------------Value------------------------------------------
   672 const Type *ConvD2INode::Value( PhaseTransform *phase ) const {
   673   const Type *t = phase->type( in(1) );
   674   if( t == Type::TOP ) return Type::TOP;
   675   if( t == Type::DOUBLE ) return TypeInt::INT;
   676   const TypeD *td = t->is_double_constant();
   677   return TypeInt::make( SharedRuntime::d2i( td->getd() ) );
   678 }
   680 //------------------------------Ideal------------------------------------------
   681 // If converting to an int type, skip any rounding nodes
   682 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
   683   if( in(1)->Opcode() == Op_RoundDouble )
   684     set_req(1,in(1)->in(1));
   685   return NULL;
   686 }
   688 //------------------------------Identity---------------------------------------
   689 // Int's can be converted to doubles with no loss of bits.  Hence
   690 // converting an integer to a double and back to an integer is a NOP.
   691 Node *ConvD2INode::Identity(PhaseTransform *phase) {
   692   return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;
   693 }
   695 //=============================================================================
   696 //------------------------------Value------------------------------------------
   697 const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {
   698   const Type *t = phase->type( in(1) );
   699   if( t == Type::TOP ) return Type::TOP;
   700   if( t == Type::DOUBLE ) return TypeLong::LONG;
   701   const TypeD *td = t->is_double_constant();
   702   return TypeLong::make( SharedRuntime::d2l( td->getd() ) );
   703 }
   705 //------------------------------Identity---------------------------------------
   706 Node *ConvD2LNode::Identity(PhaseTransform *phase) {
   707   // Remove ConvD2L->ConvL2D->ConvD2L sequences.
   708   if( in(1)       ->Opcode() == Op_ConvL2D &&
   709       in(1)->in(1)->Opcode() == Op_ConvD2L )
   710     return in(1)->in(1);
   711   return this;
   712 }
   714 //------------------------------Ideal------------------------------------------
   715 // If converting to an int type, skip any rounding nodes
   716 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   717   if( in(1)->Opcode() == Op_RoundDouble )
   718     set_req(1,in(1)->in(1));
   719   return NULL;
   720 }
   722 //=============================================================================
   723 //------------------------------Value------------------------------------------
   724 const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {
   725   const Type *t = phase->type( in(1) );
   726   if( t == Type::TOP ) return Type::TOP;
   727   if( t == Type::FLOAT ) return Type::DOUBLE;
   728   const TypeF *tf = t->is_float_constant();
   729 #ifndef IA64
   730   return TypeD::make( (double)tf->getf() );
   731 #else
   732   float x = tf->getf();
   733   return TypeD::make( (x == 0.0f) ? (double)x : (double)x + ia64_double_zero );
   734 #endif
   735 }
   737 //=============================================================================
   738 //------------------------------Value------------------------------------------
   739 const Type *ConvF2INode::Value( PhaseTransform *phase ) const {
   740   const Type *t = phase->type( in(1) );
   741   if( t == Type::TOP )       return Type::TOP;
   742   if( t == Type::FLOAT ) return TypeInt::INT;
   743   const TypeF *tf = t->is_float_constant();
   744   return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );
   745 }
   747 //------------------------------Identity---------------------------------------
   748 Node *ConvF2INode::Identity(PhaseTransform *phase) {
   749   // Remove ConvF2I->ConvI2F->ConvF2I sequences.
   750   if( in(1)       ->Opcode() == Op_ConvI2F &&
   751       in(1)->in(1)->Opcode() == Op_ConvF2I )
   752     return in(1)->in(1);
   753   return this;
   754 }
   756 //------------------------------Ideal------------------------------------------
   757 // If converting to an int type, skip any rounding nodes
   758 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
   759   if( in(1)->Opcode() == Op_RoundFloat )
   760     set_req(1,in(1)->in(1));
   761   return NULL;
   762 }
   764 //=============================================================================
   765 //------------------------------Value------------------------------------------
   766 const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {
   767   const Type *t = phase->type( in(1) );
   768   if( t == Type::TOP )       return Type::TOP;
   769   if( t == Type::FLOAT ) return TypeLong::LONG;
   770   const TypeF *tf = t->is_float_constant();
   771   return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );
   772 }
   774 //------------------------------Identity---------------------------------------
   775 Node *ConvF2LNode::Identity(PhaseTransform *phase) {
   776   // Remove ConvF2L->ConvL2F->ConvF2L sequences.
   777   if( in(1)       ->Opcode() == Op_ConvL2F &&
   778       in(1)->in(1)->Opcode() == Op_ConvF2L )
   779     return in(1)->in(1);
   780   return this;
   781 }
   783 //------------------------------Ideal------------------------------------------
   784 // If converting to an int type, skip any rounding nodes
   785 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   786   if( in(1)->Opcode() == Op_RoundFloat )
   787     set_req(1,in(1)->in(1));
   788   return NULL;
   789 }
   791 //=============================================================================
   792 //------------------------------Value------------------------------------------
   793 const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {
   794   const Type *t = phase->type( in(1) );
   795   if( t == Type::TOP ) return Type::TOP;
   796   const TypeInt *ti = t->is_int();
   797   if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );
   798   return bottom_type();
   799 }
   801 //=============================================================================
   802 //------------------------------Value------------------------------------------
   803 const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {
   804   const Type *t = phase->type( in(1) );
   805   if( t == Type::TOP ) return Type::TOP;
   806   const TypeInt *ti = t->is_int();
   807   if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );
   808   return bottom_type();
   809 }
   811 //------------------------------Identity---------------------------------------
   812 Node *ConvI2FNode::Identity(PhaseTransform *phase) {
   813   // Remove ConvI2F->ConvF2I->ConvI2F sequences.
   814   if( in(1)       ->Opcode() == Op_ConvF2I &&
   815       in(1)->in(1)->Opcode() == Op_ConvI2F )
   816     return in(1)->in(1);
   817   return this;
   818 }
   820 //=============================================================================
   821 //------------------------------Value------------------------------------------
   822 const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {
   823   const Type *t = phase->type( in(1) );
   824   if( t == Type::TOP ) return Type::TOP;
   825   const TypeInt *ti = t->is_int();
   826   const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);
   827   // Join my declared type against my incoming type.
   828   tl = tl->filter(_type);
   829   return tl;
   830 }
   832 #ifdef _LP64
   833 static inline bool long_ranges_overlap(jlong lo1, jlong hi1,
   834                                        jlong lo2, jlong hi2) {
   835   // Two ranges overlap iff one range's low point falls in the other range.
   836   return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);
   837 }
   838 #endif
   840 //------------------------------Ideal------------------------------------------
   841 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   842   const TypeLong* this_type = this->type()->is_long();
   843   Node* this_changed = NULL;
   845   // If _major_progress, then more loop optimizations follow.  Do NOT
   846   // remove this node's type assertion until no more loop ops can happen.
   847   // The progress bit is set in the major loop optimizations THEN comes the
   848   // call to IterGVN and any chance of hitting this code.  Cf. Opaque1Node.
   849   if (can_reshape && !phase->C->major_progress()) {
   850     const TypeInt* in_type = phase->type(in(1))->isa_int();
   851     if (in_type != NULL && this_type != NULL &&
   852         (in_type->_lo != this_type->_lo ||
   853          in_type->_hi != this_type->_hi)) {
   854       // Although this WORSENS the type, it increases GVN opportunities,
   855       // because I2L nodes with the same input will common up, regardless
   856       // of slightly differing type assertions.  Such slight differences
   857       // arise routinely as a result of loop unrolling, so this is a
   858       // post-unrolling graph cleanup.  Choose a type which depends only
   859       // on my input.  (Exception:  Keep a range assertion of >=0 or <0.)
   860       jlong lo1 = this_type->_lo;
   861       jlong hi1 = this_type->_hi;
   862       int   w1  = this_type->_widen;
   863       if (lo1 != (jint)lo1 ||
   864           hi1 != (jint)hi1 ||
   865           lo1 > hi1) {
   866         // Overflow leads to wraparound, wraparound leads to range saturation.
   867         lo1 = min_jint; hi1 = max_jint;
   868       } else if (lo1 >= 0) {
   869         // Keep a range assertion of >=0.
   870         lo1 = 0;        hi1 = max_jint;
   871       } else if (hi1 < 0) {
   872         // Keep a range assertion of <0.
   873         lo1 = min_jint; hi1 = -1;
   874       } else {
   875         lo1 = min_jint; hi1 = max_jint;
   876       }
   877       const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
   878                                              MIN2((jlong)in_type->_hi, hi1),
   879                                              MAX2((int)in_type->_widen, w1));
   880       if (wtype != type()) {
   881         set_type(wtype);
   882         // Note: this_type still has old type value, for the logic below.
   883         this_changed = this;
   884       }
   885     }
   886   }
   888 #ifdef _LP64
   889   // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) ,
   890   // but only if x and y have subranges that cannot cause 32-bit overflow,
   891   // under the assumption that x+y is in my own subrange this->type().
   893   // This assumption is based on a constraint (i.e., type assertion)
   894   // established in Parse::array_addressing or perhaps elsewhere.
   895   // This constraint has been adjoined to the "natural" type of
   896   // the incoming argument in(0).  We know (because of runtime
   897   // checks) - that the result value I2L(x+y) is in the joined range.
   898   // Hence we can restrict the incoming terms (x, y) to values such
   899   // that their sum also lands in that range.
   901   // This optimization is useful only on 64-bit systems, where we hope
   902   // the addition will end up subsumed in an addressing mode.
   903   // It is necessary to do this when optimizing an unrolled array
   904   // copy loop such as x[i++] = y[i++].
   906   // On 32-bit systems, it's better to perform as much 32-bit math as
   907   // possible before the I2L conversion, because 32-bit math is cheaper.
   908   // There's no common reason to "leak" a constant offset through the I2L.
   909   // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
   911   Node* z = in(1);
   912   int op = z->Opcode();
   913   if (op == Op_AddI || op == Op_SubI) {
   914     Node* x = z->in(1);
   915     Node* y = z->in(2);
   916     assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
   917     if (phase->type(x) == Type::TOP)  return this_changed;
   918     if (phase->type(y) == Type::TOP)  return this_changed;
   919     const TypeInt*  tx = phase->type(x)->is_int();
   920     const TypeInt*  ty = phase->type(y)->is_int();
   921     const TypeLong* tz = this_type;
   922     jlong xlo = tx->_lo;
   923     jlong xhi = tx->_hi;
   924     jlong ylo = ty->_lo;
   925     jlong yhi = ty->_hi;
   926     jlong zlo = tz->_lo;
   927     jlong zhi = tz->_hi;
   928     jlong vbit = CONST64(1) << BitsPerInt;
   929     int widen =  MAX2(tx->_widen, ty->_widen);
   930     if (op == Op_SubI) {
   931       jlong ylo0 = ylo;
   932       ylo = -yhi;
   933       yhi = -ylo0;
   934     }
   935     // See if x+y can cause positive overflow into z+2**32
   936     if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {
   937       return this_changed;
   938     }
   939     // See if x+y can cause negative overflow into z-2**32
   940     if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {
   941       return this_changed;
   942     }
   943     // Now it's always safe to assume x+y does not overflow.
   944     // This is true even if some pairs x,y might cause overflow, as long
   945     // as that overflow value cannot fall into [zlo,zhi].
   947     // Confident that the arithmetic is "as if infinite precision",
   948     // we can now use z's range to put constraints on those of x and y.
   949     // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a
   950     // more "restricted" range by intersecting [xlo,xhi] with the
   951     // range obtained by subtracting y's range from the asserted range
   952     // of the I2L conversion.  Here's the interval arithmetic algebra:
   953     //    x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
   954     //    => x in [zlo-yhi, zhi-ylo]
   955     //    => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
   956     //    => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
   957     jlong rxlo = MAX2(xlo, zlo - yhi);
   958     jlong rxhi = MIN2(xhi, zhi - ylo);
   959     // And similarly, x changing place with y:
   960     jlong rylo = MAX2(ylo, zlo - xhi);
   961     jlong ryhi = MIN2(yhi, zhi - xlo);
   962     if (rxlo > rxhi || rylo > ryhi) {
   963       return this_changed;  // x or y is dying; don't mess w/ it
   964     }
   965     if (op == Op_SubI) {
   966       jlong rylo0 = rylo;
   967       rylo = -ryhi;
   968       ryhi = -rylo0;
   969     }
   971     Node* cx = phase->transform( new (phase->C, 2) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) );
   972     Node* cy = phase->transform( new (phase->C, 2) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) );
   973     switch (op) {
   974     case Op_AddI:  return new (phase->C, 3) AddLNode(cx, cy);
   975     case Op_SubI:  return new (phase->C, 3) SubLNode(cx, cy);
   976     default:       ShouldNotReachHere();
   977     }
   978   }
   979 #endif //_LP64
   981   return this_changed;
   982 }
   984 //=============================================================================
   985 //------------------------------Value------------------------------------------
   986 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
   987   const Type *t = phase->type( in(1) );
   988   if( t == Type::TOP ) return Type::TOP;
   989   const TypeLong *tl = t->is_long();
   990   if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
   991   return bottom_type();
   992 }
   994 //=============================================================================
   995 //------------------------------Value------------------------------------------
   996 const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {
   997   const Type *t = phase->type( in(1) );
   998   if( t == Type::TOP ) return Type::TOP;
   999   const TypeLong *tl = t->is_long();
  1000   if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );
  1001   return bottom_type();
  1004 //=============================================================================
  1005 //----------------------------Identity-----------------------------------------
  1006 Node *ConvL2INode::Identity( PhaseTransform *phase ) {
  1007   // Convert L2I(I2L(x)) => x
  1008   if (in(1)->Opcode() == Op_ConvI2L)  return in(1)->in(1);
  1009   return this;
  1012 //------------------------------Value------------------------------------------
  1013 const Type *ConvL2INode::Value( PhaseTransform *phase ) const {
  1014   const Type *t = phase->type( in(1) );
  1015   if( t == Type::TOP ) return Type::TOP;
  1016   const TypeLong *tl = t->is_long();
  1017   if (tl->is_con())
  1018     // Easy case.
  1019     return TypeInt::make((jint)tl->get_con());
  1020   return bottom_type();
  1023 //------------------------------Ideal------------------------------------------
  1024 // Return a node which is more "ideal" than the current node.
  1025 // Blow off prior masking to int
  1026 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
  1027   Node *andl = in(1);
  1028   uint andl_op = andl->Opcode();
  1029   if( andl_op == Op_AndL ) {
  1030     // Blow off prior masking to int
  1031     if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {
  1032       set_req(1,andl->in(1));
  1033       return this;
  1037   // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
  1038   // This replaces an 'AddL' with an 'AddI'.
  1039   if( andl_op == Op_AddL ) {
  1040     // Don't do this for nodes which have more than one user since
  1041     // we'll end up computing the long add anyway.
  1042     if (andl->outcnt() > 1) return NULL;
  1044     Node* x = andl->in(1);
  1045     Node* y = andl->in(2);
  1046     assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );
  1047     if (phase->type(x) == Type::TOP)  return NULL;
  1048     if (phase->type(y) == Type::TOP)  return NULL;
  1049     Node *add1 = phase->transform(new (phase->C, 2) ConvL2INode(x));
  1050     Node *add2 = phase->transform(new (phase->C, 2) ConvL2INode(y));
  1051     return new (phase->C, 3) AddINode(add1,add2);
  1054   // Disable optimization: LoadL->ConvL2I ==> LoadI.
  1055   // It causes problems (sizes of Load and Store nodes do not match)
  1056   // in objects initialization code and Escape Analysis.
  1057   return NULL;
  1060 //=============================================================================
  1061 //------------------------------Value------------------------------------------
  1062 const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
  1063   const Type* t = phase->type(in(1));
  1064   if (t->base() == Type_X && t->singleton()) {
  1065     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
  1066     if (bits == 0)   return TypePtr::NULL_PTR;
  1067     return TypeRawPtr::make((address) bits);
  1069   return CastX2PNode::bottom_type();
  1072 //------------------------------Idealize---------------------------------------
  1073 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
  1074   if (t == Type::TOP)  return false;
  1075   const TypeX* tl = t->is_intptr_t();
  1076   jint lo = min_jint;
  1077   jint hi = max_jint;
  1078   if (but_not_min_int)  ++lo;  // caller wants to negate the value w/o overflow
  1079   return (tl->_lo >= lo) && (tl->_hi <= hi);
  1082 static inline Node* addP_of_X2P(PhaseGVN *phase,
  1083                                 Node* base,
  1084                                 Node* dispX,
  1085                                 bool negate = false) {
  1086   if (negate) {
  1087     dispX = new (phase->C, 3) SubXNode(phase->MakeConX(0), phase->transform(dispX));
  1089   return new (phase->C, 4) AddPNode(phase->C->top(),
  1090                           phase->transform(new (phase->C, 2) CastX2PNode(base)),
  1091                           phase->transform(dispX));
  1094 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
  1095   // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
  1096   int op = in(1)->Opcode();
  1097   Node* x;
  1098   Node* y;
  1099   switch (op) {
  1100   case Op_SubX:
  1101     x = in(1)->in(1);
  1102     y = in(1)->in(2);
  1103     if (fits_in_int(phase->type(y), true)) {
  1104       return addP_of_X2P(phase, x, y, true);
  1106     break;
  1107   case Op_AddX:
  1108     x = in(1)->in(1);
  1109     y = in(1)->in(2);
  1110     if (fits_in_int(phase->type(y))) {
  1111       return addP_of_X2P(phase, x, y);
  1113     if (fits_in_int(phase->type(x))) {
  1114       return addP_of_X2P(phase, y, x);
  1116     break;
  1118   return NULL;
  1121 //------------------------------Identity---------------------------------------
  1122 Node *CastX2PNode::Identity( PhaseTransform *phase ) {
  1123   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
  1124   return this;
  1127 //=============================================================================
  1128 //------------------------------Value------------------------------------------
  1129 const Type *CastP2XNode::Value( PhaseTransform *phase ) const {
  1130   const Type* t = phase->type(in(1));
  1131   if (t->base() == Type::RawPtr && t->singleton()) {
  1132     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
  1133     return TypeX::make(bits);
  1135   return CastP2XNode::bottom_type();
  1138 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
  1139   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
  1142 //------------------------------Identity---------------------------------------
  1143 Node *CastP2XNode::Identity( PhaseTransform *phase ) {
  1144   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
  1145   return this;
  1149 //=============================================================================
  1150 //------------------------------Identity---------------------------------------
  1151 // Remove redundant roundings
  1152 Node *RoundFloatNode::Identity( PhaseTransform *phase ) {
  1153   assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
  1154   // Do not round constants
  1155   if (phase->type(in(1))->base() == Type::FloatCon)  return in(1);
  1156   int op = in(1)->Opcode();
  1157   // Redundant rounding
  1158   if( op == Op_RoundFloat ) return in(1);
  1159   // Already rounded
  1160   if( op == Op_Parm ) return in(1);
  1161   if( op == Op_LoadF ) return in(1);
  1162   return this;
  1165 //------------------------------Value------------------------------------------
  1166 const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {
  1167   return phase->type( in(1) );
  1170 //=============================================================================
  1171 //------------------------------Identity---------------------------------------
  1172 // Remove redundant roundings.  Incoming arguments are already rounded.
  1173 Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {
  1174   assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
  1175   // Do not round constants
  1176   if (phase->type(in(1))->base() == Type::DoubleCon)  return in(1);
  1177   int op = in(1)->Opcode();
  1178   // Redundant rounding
  1179   if( op == Op_RoundDouble ) return in(1);
  1180   // Already rounded
  1181   if( op == Op_Parm ) return in(1);
  1182   if( op == Op_LoadD ) return in(1);
  1183   if( op == Op_ConvF2D ) return in(1);
  1184   if( op == Op_ConvI2D ) return in(1);
  1185   return this;
  1188 //------------------------------Value------------------------------------------
  1189 const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {
  1190   return phase->type( in(1) );
  1194 //=============================================================================
  1195 // Do not allow value-numbering
  1196 uint Opaque1Node::hash() const { return NO_HASH; }
  1197 uint Opaque1Node::cmp( const Node &n ) const {
  1198   return (&n == this);          // Always fail except on self
  1201 //------------------------------Identity---------------------------------------
  1202 // If _major_progress, then more loop optimizations follow.  Do NOT remove
  1203 // the opaque Node until no more loop ops can happen.  Note the timing of
  1204 // _major_progress; it's set in the major loop optimizations THEN comes the
  1205 // call to IterGVN and any chance of hitting this code.  Hence there's no
  1206 // phase-ordering problem with stripping Opaque1 in IGVN followed by some
  1207 // more loop optimizations that require it.
  1208 Node *Opaque1Node::Identity( PhaseTransform *phase ) {
  1209   return phase->C->major_progress() ? this : in(1);
  1212 //=============================================================================
  1213 // A node to prevent unwanted optimizations.  Allows constant folding.  Stops
  1214 // value-numbering, most Ideal calls or Identity functions.  This Node is
  1215 // specifically designed to prevent the pre-increment value of a loop trip
  1216 // counter from being live out of the bottom of the loop (hence causing the
  1217 // pre- and post-increment values both being live and thus requiring an extra
  1218 // temp register and an extra move).  If we "accidentally" optimize through
  1219 // this kind of a Node, we'll get slightly pessimal, but correct, code.  Thus
  1220 // it's OK to be slightly sloppy on optimizations here.
  1222 // Do not allow value-numbering
  1223 uint Opaque2Node::hash() const { return NO_HASH; }
  1224 uint Opaque2Node::cmp( const Node &n ) const {
  1225   return (&n == this);          // Always fail except on self
  1229 //------------------------------Value------------------------------------------
  1230 const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {
  1231   const Type *t = phase->type( in(1) );
  1232   if( t == Type::TOP ) return Type::TOP;
  1233   const TypeLong *tl = t->is_long();
  1234   if( !tl->is_con() ) return bottom_type();
  1235   JavaValue v;
  1236   v.set_jlong(tl->get_con());
  1237   return TypeD::make( v.get_jdouble() );
  1240 //------------------------------Value------------------------------------------
  1241 const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {
  1242   const Type *t = phase->type( in(1) );
  1243   if( t == Type::TOP ) return Type::TOP;
  1244   const TypeInt *ti = t->is_int();
  1245   if( !ti->is_con() )   return bottom_type();
  1246   JavaValue v;
  1247   v.set_jint(ti->get_con());
  1248   return TypeF::make( v.get_jfloat() );
  1251 //------------------------------Value------------------------------------------
  1252 const Type *MoveF2INode::Value( PhaseTransform *phase ) const {
  1253   const Type *t = phase->type( in(1) );
  1254   if( t == Type::TOP )       return Type::TOP;
  1255   if( t == Type::FLOAT ) return TypeInt::INT;
  1256   const TypeF *tf = t->is_float_constant();
  1257   JavaValue v;
  1258   v.set_jfloat(tf->getf());
  1259   return TypeInt::make( v.get_jint() );
  1262 //------------------------------Value------------------------------------------
  1263 const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {
  1264   const Type *t = phase->type( in(1) );
  1265   if( t == Type::TOP ) return Type::TOP;
  1266   if( t == Type::DOUBLE ) return TypeLong::LONG;
  1267   const TypeD *td = t->is_double_constant();
  1268   JavaValue v;
  1269   v.set_jdouble(td->getd());
  1270   return TypeLong::make( v.get_jlong() );

mercurial