src/share/vm/opto/connode.cpp

Mon, 17 Sep 2012 19:39:07 -0700

author
kvn
date
Mon, 17 Sep 2012 19:39:07 -0700
changeset 4103
137868b7aa6f
parent 4037
da91efe96a93
child 4106
7eca5de9e0b6
permissions
-rw-r--r--

7196199: java/text/Bidi/Bug6665028.java failed: Bidi run count incorrect
Summary: Save whole XMM/YMM registers in safepoint interrupt handler.
Reviewed-by: roland, twisti

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

mercurial