src/share/vm/opto/connode.cpp

Wed, 10 Aug 2016 14:59:21 +0200

author
simonis
date
Wed, 10 Aug 2016 14:59:21 +0200
changeset 8608
0d78aecb0948
parent 8435
64bd5b63923c
child 8604
04d83ba48607
child 8727
3d8d14307428
permissions
-rw-r--r--

8152172: PPC64: Support AES intrinsics
Summary: Add support for AES intrinsics on PPC64.
Reviewed-by: kvn, mdoerr, simonis, zmajo
Contributed-by: Hiroshi H Horii <horii@jp.ibm.com>

     1 /*
     2  * Copyright (c) 1997, 2013, 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) ConINode( t->is_int() );
    49   case T_LONG:        return new (C) ConLNode( t->is_long() );
    50   case T_FLOAT:       return new (C) ConFNode( t->is_float_constant() );
    51   case T_DOUBLE:      return new (C) ConDNode( t->is_double_constant() );
    52   case T_VOID:        return new (C) ConNode ( Type::TOP );
    53   case T_OBJECT:      return new (C) ConPNode( t->is_ptr() );
    54   case T_ARRAY:       return new (C) ConPNode( t->is_aryptr() );
    55   case T_ADDRESS:     return new (C) ConPNode( t->is_ptr() );
    56   case T_NARROWOOP:   return new (C) ConNNode( t->is_narrowoop() );
    57   case T_NARROWKLASS: return new (C) ConNKlassNode( t->is_narrowklass() );
    58   case T_METADATA:    return new (C) ConPNode( t->is_ptr() );
    59     // Expected cases:  TypePtr::NULL_PTR, any is_rawptr()
    60     // Also seen: AnyPtr(TopPTR *+top); from command line:
    61     //   r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=660
    62     // %%%% Stop using TypePtr::NULL_PTR to represent nulls:  use either TypeRawPtr::NULL_PTR
    63     // or else TypeOopPtr::NULL_PTR.  Then set Type::_basic_type[AnyPtr] = T_ILLEGAL
    64   }
    65   ShouldNotReachHere();
    66   return NULL;
    67 }
    69 //=============================================================================
    70 /*
    71 The major change is for CMoveP and StrComp.  They have related but slightly
    72 different problems.  They both take in TWO oops which are both null-checked
    73 independently before the using Node.  After CCP removes the CastPP's they need
    74 to pick up the guarding test edge - in this case TWO control edges.  I tried
    75 various solutions, all have problems:
    77 (1) Do nothing.  This leads to a bug where we hoist a Load from a CMoveP or a
    78 StrComp above a guarding null check.  I've seen both cases in normal -Xcomp
    79 testing.
    81 (2) Plug the control edge from 1 of the 2 oops in.  Apparent problem here is
    82 to figure out which test post-dominates.  The real problem is that it doesn't
    83 matter which one you pick.  After you pick up, the dominating-test elider in
    84 IGVN can remove the test and allow you to hoist up to the dominating test on
    85 the chosen oop bypassing the test on the not-chosen oop.  Seen in testing.
    86 Oops.
    88 (3) Leave the CastPP's in.  This makes the graph more accurate in some sense;
    89 we get to keep around the knowledge that an oop is not-null after some test.
    90 Alas, the CastPP's interfere with GVN (some values are the regular oop, some
    91 are the CastPP of the oop, all merge at Phi's which cannot collapse, etc).
    92 This cost us 10% on SpecJVM, even when I removed some of the more trivial
    93 cases in the optimizer.  Removing more useless Phi's started allowing Loads to
    94 illegally float above null checks.  I gave up on this approach.
    96 (4) Add BOTH control edges to both tests.  Alas, too much code knows that
    97 control edges are in slot-zero ONLY.  Many quick asserts fail; no way to do
    98 this one.  Note that I really want to allow the CMoveP to float and add both
    99 control edges to the dependent Load op - meaning I can select early but I
   100 cannot Load until I pass both tests.
   102 (5) Do not hoist CMoveP and StrComp.  To this end I added the v-call
   103 depends_only_on_test().  No obvious performance loss on Spec, but we are
   104 clearly conservative on CMoveP (also so on StrComp but that's unlikely to
   105 matter ever).
   107 */
   110 //------------------------------Ideal------------------------------------------
   111 // Return a node which is more "ideal" than the current node.
   112 // Move constants to the right.
   113 Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   114   if( in(0) && remove_dead_region(phase, can_reshape) ) return this;
   115   // Don't bother trying to transform a dead node
   116   if( in(0) && in(0)->is_top() )  return NULL;
   117   assert( !phase->eqv(in(Condition), this) &&
   118           !phase->eqv(in(IfFalse), this) &&
   119           !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
   120   if( phase->type(in(Condition)) == Type::TOP )
   121     return NULL; // return NULL when Condition is dead
   123   if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {
   124     if( in(Condition)->is_Bool() ) {
   125       BoolNode* b  = in(Condition)->as_Bool();
   126       BoolNode* b2 = b->negate(phase);
   127       return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
   128     }
   129   }
   130   return NULL;
   131 }
   133 //------------------------------is_cmove_id------------------------------------
   134 // Helper function to check for CMOVE identity.  Shared with PhiNode::Identity
   135 Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
   136   // Check for Cmp'ing and CMove'ing same values
   137   if( (phase->eqv(cmp->in(1),f) &&
   138        phase->eqv(cmp->in(2),t)) ||
   139       // Swapped Cmp is OK
   140       (phase->eqv(cmp->in(2),f) &&
   141        phase->eqv(cmp->in(1),t)) ) {
   142     // Give up this identity check for floating points because it may choose incorrect
   143     // value around 0.0 and -0.0
   144     if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD )
   145       return NULL;
   146     // Check for "(t==f)?t:f;" and replace with "f"
   147     if( b->_test._test == BoolTest::eq )
   148       return f;
   149     // Allow the inverted case as well
   150     // Check for "(t!=f)?t:f;" and replace with "t"
   151     if( b->_test._test == BoolTest::ne )
   152       return t;
   153   }
   154   return NULL;
   155 }
   157 //------------------------------Identity---------------------------------------
   158 // Conditional-move is an identity if both inputs are the same, or the test
   159 // true or false.
   160 Node *CMoveNode::Identity( PhaseTransform *phase ) {
   161   if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?
   162     return in(IfFalse);         // Then it doesn't matter
   163   if( phase->type(in(Condition)) == TypeInt::ZERO )
   164     return in(IfFalse);         // Always pick left(false) input
   165   if( phase->type(in(Condition)) == TypeInt::ONE )
   166     return in(IfTrue);          // Always pick right(true) input
   168   // Check for CMove'ing a constant after comparing against the constant.
   169   // Happens all the time now, since if we compare equality vs a constant in
   170   // the parser, we "know" the variable is constant on one path and we force
   171   // it.  Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a
   172   // conditional move: "x = (x==0)?0:x;".  Yucko.  This fix is slightly more
   173   // general in that we don't need constants.
   174   if( in(Condition)->is_Bool() ) {
   175     BoolNode *b = in(Condition)->as_Bool();
   176     Node *cmp = b->in(1);
   177     if( cmp->is_Cmp() ) {
   178       Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );
   179       if( id ) return id;
   180     }
   181   }
   183   return this;
   184 }
   186 //------------------------------Value------------------------------------------
   187 // Result is the meet of inputs
   188 const Type *CMoveNode::Value( PhaseTransform *phase ) const {
   189   if( phase->type(in(Condition)) == Type::TOP )
   190     return Type::TOP;
   191   return phase->type(in(IfFalse))->meet_speculative(phase->type(in(IfTrue)));
   192 }
   194 //------------------------------make-------------------------------------------
   195 // Make a correctly-flavored CMove.  Since _type is directly determined
   196 // from the inputs we do not need to specify it here.
   197 CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) {
   198   switch( t->basic_type() ) {
   199   case T_INT:     return new (C) CMoveINode( bol, left, right, t->is_int() );
   200   case T_FLOAT:   return new (C) CMoveFNode( bol, left, right, t );
   201   case T_DOUBLE:  return new (C) CMoveDNode( bol, left, right, t );
   202   case T_LONG:    return new (C) CMoveLNode( bol, left, right, t->is_long() );
   203   case T_OBJECT:  return new (C) CMovePNode( c, bol, left, right, t->is_oopptr() );
   204   case T_ADDRESS: return new (C) CMovePNode( c, bol, left, right, t->is_ptr() );
   205   case T_NARROWOOP: return new (C) CMoveNNode( c, bol, left, right, t );
   206   default:
   207     ShouldNotReachHere();
   208     return NULL;
   209   }
   210 }
   212 //=============================================================================
   213 //------------------------------Ideal------------------------------------------
   214 // Return a node which is more "ideal" than the current node.
   215 // Check for conversions to boolean
   216 Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
   217   // Try generic ideal's first
   218   Node *x = CMoveNode::Ideal(phase, can_reshape);
   219   if( x ) return x;
   221   // If zero is on the left (false-case, no-move-case) it must mean another
   222   // constant is on the right (otherwise the shared CMove::Ideal code would
   223   // have moved the constant to the right).  This situation is bad for Intel
   224   // and a don't-care for Sparc.  It's bad for Intel because the zero has to
   225   // be manifested in a register with a XOR which kills flags, which are live
   226   // on input to the CMoveI, leading to a situation which causes excessive
   227   // spilling on Intel.  For Sparc, if the zero in on the left the Sparc will
   228   // zero a register via G0 and conditionally-move the other constant.  If the
   229   // zero is on the right, the Sparc will load the first constant with a
   230   // 13-bit set-lo and conditionally move G0.  See bug 4677505.
   231   if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
   232     if( in(Condition)->is_Bool() ) {
   233       BoolNode* b  = in(Condition)->as_Bool();
   234       BoolNode* b2 = b->negate(phase);
   235       return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
   236     }
   237   }
   239   // Now check for booleans
   240   int flip = 0;
   242   // Check for picking from zero/one
   243   if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
   244     flip = 1 - flip;
   245   } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
   246   } else return NULL;
   248   // Check for eq/ne test
   249   if( !in(1)->is_Bool() ) return NULL;
   250   BoolNode *bol = in(1)->as_Bool();
   251   if( bol->_test._test == BoolTest::eq ) {
   252   } else if( bol->_test._test == BoolTest::ne ) {
   253     flip = 1-flip;
   254   } else return NULL;
   256   // Check for vs 0 or 1
   257   if( !bol->in(1)->is_Cmp() ) return NULL;
   258   const CmpNode *cmp = bol->in(1)->as_Cmp();
   259   if( phase->type(cmp->in(2)) == TypeInt::ZERO ) {
   260   } else if( phase->type(cmp->in(2)) == TypeInt::ONE ) {
   261     // Allow cmp-vs-1 if the other input is bounded by 0-1
   262     if( phase->type(cmp->in(1)) != TypeInt::BOOL )
   263       return NULL;
   264     flip = 1 - flip;
   265   } else return NULL;
   267   // Convert to a bool (flipped)
   268   // Build int->bool conversion
   269 #ifndef PRODUCT
   270   if( PrintOpto ) tty->print_cr("CMOV to I2B");
   271 #endif
   272   Node *n = new (phase->C) Conv2BNode( cmp->in(1) );
   273   if( flip )
   274     n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );
   276   return n;
   277 }
   279 //=============================================================================
   280 //------------------------------Ideal------------------------------------------
   281 // Return a node which is more "ideal" than the current node.
   282 // Check for absolute value
   283 Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   284   // Try generic ideal's first
   285   Node *x = CMoveNode::Ideal(phase, can_reshape);
   286   if( x ) return x;
   288   int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
   289   int  phi_x_idx = 0;           // Index of phi input where to find naked x
   291   // Find the Bool
   292   if( !in(1)->is_Bool() ) return NULL;
   293   BoolNode *bol = in(1)->as_Bool();
   294   // Check bool sense
   295   switch( bol->_test._test ) {
   296   case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
   297   case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
   298   case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
   299   case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
   300   default:           return NULL;                           break;
   301   }
   303   // Find zero input of CmpF; the other input is being abs'd
   304   Node *cmpf = bol->in(1);
   305   if( cmpf->Opcode() != Op_CmpF ) return NULL;
   306   Node *X = NULL;
   307   bool flip = false;
   308   if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
   309     X = cmpf->in(3 - cmp_zero_idx);
   310   } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
   311     // The test is inverted, we should invert the result...
   312     X = cmpf->in(cmp_zero_idx);
   313     flip = true;
   314   } else {
   315     return NULL;
   316   }
   318   // If X is found on the appropriate phi input, find the subtract on the other
   319   if( X != in(phi_x_idx) ) return NULL;
   320   int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
   321   Node *sub = in(phi_sub_idx);
   323   // Allow only SubF(0,X) and fail out for all others; NegF is not OK
   324   if( sub->Opcode() != Op_SubF ||
   325       sub->in(2) != X ||
   326       phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
   328   Node *abs = new (phase->C) AbsFNode( X );
   329   if( flip )
   330     abs = new (phase->C) SubFNode(sub->in(1), phase->transform(abs));
   332   return abs;
   333 }
   335 //=============================================================================
   336 //------------------------------Ideal------------------------------------------
   337 // Return a node which is more "ideal" than the current node.
   338 // Check for absolute value
   339 Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   340   // Try generic ideal's first
   341   Node *x = CMoveNode::Ideal(phase, can_reshape);
   342   if( x ) return x;
   344   int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
   345   int  phi_x_idx = 0;           // Index of phi input where to find naked x
   347   // Find the Bool
   348   if( !in(1)->is_Bool() ) return NULL;
   349   BoolNode *bol = in(1)->as_Bool();
   350   // Check bool sense
   351   switch( bol->_test._test ) {
   352   case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
   353   case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
   354   case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
   355   case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
   356   default:           return NULL;                           break;
   357   }
   359   // Find zero input of CmpD; the other input is being abs'd
   360   Node *cmpd = bol->in(1);
   361   if( cmpd->Opcode() != Op_CmpD ) return NULL;
   362   Node *X = NULL;
   363   bool flip = false;
   364   if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
   365     X = cmpd->in(3 - cmp_zero_idx);
   366   } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
   367     // The test is inverted, we should invert the result...
   368     X = cmpd->in(cmp_zero_idx);
   369     flip = true;
   370   } else {
   371     return NULL;
   372   }
   374   // If X is found on the appropriate phi input, find the subtract on the other
   375   if( X != in(phi_x_idx) ) return NULL;
   376   int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
   377   Node *sub = in(phi_sub_idx);
   379   // Allow only SubD(0,X) and fail out for all others; NegD is not OK
   380   if( sub->Opcode() != Op_SubD ||
   381       sub->in(2) != X ||
   382       phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
   384   Node *abs = new (phase->C) AbsDNode( X );
   385   if( flip )
   386     abs = new (phase->C) SubDNode(sub->in(1), phase->transform(abs));
   388   return abs;
   389 }
   392 //=============================================================================
   393 // If input is already higher or equal to cast type, then this is an identity.
   394 Node *ConstraintCastNode::Identity( PhaseTransform *phase ) {
   395   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
   396 }
   398 //------------------------------Value------------------------------------------
   399 // Take 'join' of input and cast-up type
   400 const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const {
   401   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
   402 const Type* ft = phase->type(in(1))->filter_speculative(_type);
   404 #ifdef ASSERT
   405   // Previous versions of this function had some special case logic,
   406   // which is no longer necessary.  Make sure of the required effects.
   407   switch (Opcode()) {
   408   case Op_CastII:
   409     {
   410       const Type* t1 = phase->type(in(1));
   411       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
   412       const Type* rt = t1->join_speculative(_type);
   413       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
   414       break;
   415     }
   416   case Op_CastPP:
   417     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
   418         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
   419       assert(ft == Type::TOP, "special case #3");
   420     break;
   421   }
   422 #endif //ASSERT
   424   return ft;
   425 }
   427 //------------------------------Ideal------------------------------------------
   428 // Return a node which is more "ideal" than the current node.  Strip out
   429 // control copies
   430 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){
   431   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
   432 }
   434 //------------------------------Ideal_DU_postCCP-------------------------------
   435 // Throw away cast after constant propagation
   436 Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
   437   const Type *t = ccp->type(in(1));
   438   ccp->hash_delete(this);
   439   set_type(t);                   // Turn into ID function
   440   ccp->hash_insert(this);
   441   return this;
   442 }
   444 uint CastIINode::size_of() const {
   445   return sizeof(*this);
   446 }
   448 uint CastIINode::cmp(const Node &n) const {
   449   return TypeNode::cmp(n) &&
   450          ((CastIINode&)n)._carry_dependency == _carry_dependency &&
   451          ((CastIINode&)n)._range_check_dependency == _range_check_dependency;
   452 }
   454 Node *CastIINode::Identity(PhaseTransform *phase) {
   455   if (_carry_dependency) {
   456     return this;
   457   }
   458   return ConstraintCastNode::Identity(phase);
   459 }
   461 const Type *CastIINode::Value(PhaseTransform *phase) const {
   462   const Type *res = ConstraintCastNode::Value(phase);
   464   // Try to improve the type of the CastII if we recognize a CmpI/If
   465   // pattern.
   466   if (_carry_dependency) {
   467     if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
   468       assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
   469       Node* proj = in(0);
   470       if (proj->in(0)->in(1)->is_Bool()) {
   471         Node* b = proj->in(0)->in(1);
   472         if (b->in(1)->Opcode() == Op_CmpI) {
   473           Node* cmp = b->in(1);
   474           if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
   475             const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
   476             const Type* t = TypeInt::INT;
   477             BoolTest test = b->as_Bool()->_test;
   478             if (proj->is_IfFalse()) {
   479               test = test.negate();
   480             }
   481             BoolTest::mask m = test._test;
   482             jlong lo_long = min_jint;
   483             jlong hi_long = max_jint;
   484             if (m == BoolTest::le || m == BoolTest::lt) {
   485               hi_long = in2_t->_hi;
   486               if (m == BoolTest::lt) {
   487                 hi_long -= 1;
   488               }
   489             } else if (m == BoolTest::ge || m == BoolTest::gt) {
   490               lo_long = in2_t->_lo;
   491               if (m == BoolTest::gt) {
   492                 lo_long += 1;
   493               }
   494             } else if (m == BoolTest::eq) {
   495               lo_long = in2_t->_lo;
   496               hi_long = in2_t->_hi;
   497             } else if (m == BoolTest::ne) {
   498               // can't do any better
   499             } else {
   500               stringStream ss;
   501               test.dump_on(&ss);
   502               fatal(err_msg_res("unexpected comparison %s", ss.as_string()));
   503             }
   504             int lo_int = (int)lo_long;
   505             int hi_int = (int)hi_long;
   507             if (lo_long != (jlong)lo_int) {
   508               lo_int = min_jint;
   509             }
   510             if (hi_long != (jlong)hi_int) {
   511               hi_int = max_jint;
   512             }
   514             t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
   516             res = res->filter_speculative(t);
   518             return res;
   519           }
   520         }
   521       }
   522     }
   523   }
   524   return res;
   525 }
   527 Node *CastIINode::Ideal_DU_postCCP(PhaseCCP *ccp) {
   528   if (_carry_dependency || _range_check_dependency) {
   529     return NULL;
   530   }
   531   return ConstraintCastNode::Ideal_DU_postCCP(ccp);
   532 }
   534 #ifndef PRODUCT
   535 void CastIINode::dump_spec(outputStream *st) const {
   536   TypeNode::dump_spec(st);
   537   if (_carry_dependency) {
   538     st->print(" carry dependency");
   539   }
   540   if (_range_check_dependency) {
   541     st->print(" range check dependency");
   542   }
   543 }
   544 #endif
   546 //=============================================================================
   548 //------------------------------Ideal_DU_postCCP-------------------------------
   549 // If not converting int->oop, throw away cast after constant propagation
   550 Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
   551   const Type *t = ccp->type(in(1));
   552   if (!t->isa_oop_ptr() || ((in(1)->is_DecodeN()) && Matcher::gen_narrow_oop_implicit_null_checks())) {
   553     return NULL; // do not transform raw pointers or narrow oops
   554   }
   555   return ConstraintCastNode::Ideal_DU_postCCP(ccp);
   556 }
   560 //=============================================================================
   561 //------------------------------Identity---------------------------------------
   562 // If input is already higher or equal to cast type, then this is an identity.
   563 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
   564   // Toned down to rescue meeting at a Phi 3 different oops all implementing
   565   // the same interface.  CompileTheWorld starting at 502, kd12rc1.zip.
   566   return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
   567 }
   569 //------------------------------Value------------------------------------------
   570 // Take 'join' of input and cast-up type, unless working with an Interface
   571 const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
   572   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
   574   const Type *inn = phase->type(in(1));
   575   if( inn == Type::TOP ) return Type::TOP;  // No information yet
   577   const TypePtr *in_type   = inn->isa_ptr();
   578   const TypePtr *my_type   = _type->isa_ptr();
   579   const Type *result = _type;
   580   if( in_type != NULL && my_type != NULL ) {
   581     TypePtr::PTR   in_ptr    = in_type->ptr();
   582     if( in_ptr == TypePtr::Null ) {
   583       result = in_type;
   584     } else if( in_ptr == TypePtr::Constant ) {
   585       // Casting a constant oop to an interface?
   586       // (i.e., a String to a Comparable?)
   587       // Then return the interface.
   588       const TypeOopPtr *jptr = my_type->isa_oopptr();
   589       assert( jptr, "" );
   590       result =  (jptr->klass()->is_interface() || !in_type->higher_equal(_type))
   591         ? my_type->cast_to_ptr_type( TypePtr::NotNull )
   592         : in_type;
   593     } else {
   594       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
   595     }
   596   }
   597   return result;
   599   // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
   600   // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
   602   //
   603   // Remove this code after overnight run indicates no performance
   604   // loss from not performing JOIN at CheckCastPPNode
   605   //
   606   // const TypeInstPtr *in_oop = in->isa_instptr();
   607   // const TypeInstPtr *my_oop = _type->isa_instptr();
   608   // // If either input is an 'interface', return destination type
   609   // assert (in_oop == NULL || in_oop->klass() != NULL, "");
   610   // assert (my_oop == NULL || my_oop->klass() != NULL, "");
   611   // if( (in_oop && in_oop->klass()->is_interface())
   612   //   ||(my_oop && my_oop->klass()->is_interface()) ) {
   613   //   TypePtr::PTR  in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
   614   //   // Preserve cast away nullness for interfaces
   615   //   if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
   616   //     return my_oop->cast_to_ptr_type(TypePtr::NotNull);
   617   //   }
   618   //   return _type;
   619   // }
   620   //
   621   // // Neither the input nor the destination type is an interface,
   622   //
   623   // // history: JOIN used to cause weird corner case bugs
   624   // //          return (in == TypeOopPtr::NULL_PTR) ? in : _type;
   625   // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
   626   // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
   627   // const Type *join = in->join(_type);
   628   // // Check if join preserved NotNull'ness for pointers
   629   // if( join->isa_ptr() && _type->isa_ptr() ) {
   630   //   TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
   631   //   TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
   632   //   // If there isn't any NotNull'ness to preserve
   633   //   // OR if join preserved NotNull'ness then return it
   634   //   if( type_ptr == TypePtr::BotPTR  || type_ptr == TypePtr::Null ||
   635   //       join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
   636   //     return join;
   637   //   }
   638   //   // ELSE return same old type as before
   639   //   return _type;
   640   // }
   641   // // Not joining two pointers
   642   // return join;
   643 }
   645 //------------------------------Ideal------------------------------------------
   646 // Return a node which is more "ideal" than the current node.  Strip out
   647 // control copies
   648 Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){
   649   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
   650 }
   653 Node* DecodeNNode::Identity(PhaseTransform* phase) {
   654   const Type *t = phase->type( in(1) );
   655   if( t == Type::TOP ) return in(1);
   657   if (in(1)->is_EncodeP()) {
   658     // (DecodeN (EncodeP p)) -> p
   659     return in(1)->in(1);
   660   }
   661   return this;
   662 }
   664 const Type *DecodeNNode::Value( PhaseTransform *phase ) const {
   665   const Type *t = phase->type( in(1) );
   666   if (t == Type::TOP) return Type::TOP;
   667   if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR;
   669   assert(t->isa_narrowoop(), "only  narrowoop here");
   670   return t->make_ptr();
   671 }
   673 Node* EncodePNode::Identity(PhaseTransform* phase) {
   674   const Type *t = phase->type( in(1) );
   675   if( t == Type::TOP ) return in(1);
   677   if (in(1)->is_DecodeN()) {
   678     // (EncodeP (DecodeN p)) -> p
   679     return in(1)->in(1);
   680   }
   681   return this;
   682 }
   684 const Type *EncodePNode::Value( PhaseTransform *phase ) const {
   685   const Type *t = phase->type( in(1) );
   686   if (t == Type::TOP) return Type::TOP;
   687   if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR;
   689   assert(t->isa_oop_ptr(), "only oopptr here");
   690   return t->make_narrowoop();
   691 }
   694 Node *EncodeNarrowPtrNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
   695   return MemNode::Ideal_common_DU_postCCP(ccp, this, in(1));
   696 }
   698 Node* DecodeNKlassNode::Identity(PhaseTransform* phase) {
   699   const Type *t = phase->type( in(1) );
   700   if( t == Type::TOP ) return in(1);
   702   if (in(1)->is_EncodePKlass()) {
   703     // (DecodeNKlass (EncodePKlass p)) -> p
   704     return in(1)->in(1);
   705   }
   706   return this;
   707 }
   709 const Type *DecodeNKlassNode::Value( PhaseTransform *phase ) const {
   710   const Type *t = phase->type( in(1) );
   711   if (t == Type::TOP) return Type::TOP;
   712   assert(t != TypeNarrowKlass::NULL_PTR, "null klass?");
   714   assert(t->isa_narrowklass(), "only narrow klass ptr here");
   715   return t->make_ptr();
   716 }
   718 Node* EncodePKlassNode::Identity(PhaseTransform* phase) {
   719   const Type *t = phase->type( in(1) );
   720   if( t == Type::TOP ) return in(1);
   722   if (in(1)->is_DecodeNKlass()) {
   723     // (EncodePKlass (DecodeNKlass p)) -> p
   724     return in(1)->in(1);
   725   }
   726   return this;
   727 }
   729 const Type *EncodePKlassNode::Value( PhaseTransform *phase ) const {
   730   const Type *t = phase->type( in(1) );
   731   if (t == Type::TOP) return Type::TOP;
   732   assert (t != TypePtr::NULL_PTR, "null klass?");
   734   assert(UseCompressedClassPointers && t->isa_klassptr(), "only klass ptr here");
   735   return t->make_narrowklass();
   736 }
   739 //=============================================================================
   740 //------------------------------Identity---------------------------------------
   741 Node *Conv2BNode::Identity( PhaseTransform *phase ) {
   742   const Type *t = phase->type( in(1) );
   743   if( t == Type::TOP ) return in(1);
   744   if( t == TypeInt::ZERO ) return in(1);
   745   if( t == TypeInt::ONE ) return in(1);
   746   if( t == TypeInt::BOOL ) return in(1);
   747   return this;
   748 }
   750 //------------------------------Value------------------------------------------
   751 const Type *Conv2BNode::Value( PhaseTransform *phase ) const {
   752   const Type *t = phase->type( in(1) );
   753   if( t == Type::TOP ) return Type::TOP;
   754   if( t == TypeInt::ZERO ) return TypeInt::ZERO;
   755   if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;
   756   const TypePtr *tp = t->isa_ptr();
   757   if( tp != NULL ) {
   758     if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;
   759     if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;
   760     if (tp->ptr() == TypePtr::NotNull)  return TypeInt::ONE;
   761     return TypeInt::BOOL;
   762   }
   763   if (t->base() != Type::Int) return TypeInt::BOOL;
   764   const TypeInt *ti = t->is_int();
   765   if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;
   766   return TypeInt::BOOL;
   767 }
   770 // The conversions operations are all Alpha sorted.  Please keep it that way!
   771 //=============================================================================
   772 //------------------------------Value------------------------------------------
   773 const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {
   774   const Type *t = phase->type( in(1) );
   775   if( t == Type::TOP ) return Type::TOP;
   776   if( t == Type::DOUBLE ) return Type::FLOAT;
   777   const TypeD *td = t->is_double_constant();
   778   return TypeF::make( (float)td->getd() );
   779 }
   781 //------------------------------Identity---------------------------------------
   782 // Float's can be converted to doubles with no loss of bits.  Hence
   783 // converting a float to a double and back to a float is a NOP.
   784 Node *ConvD2FNode::Identity(PhaseTransform *phase) {
   785   return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;
   786 }
   788 //=============================================================================
   789 //------------------------------Value------------------------------------------
   790 const Type *ConvD2INode::Value( PhaseTransform *phase ) const {
   791   const Type *t = phase->type( in(1) );
   792   if( t == Type::TOP ) return Type::TOP;
   793   if( t == Type::DOUBLE ) return TypeInt::INT;
   794   const TypeD *td = t->is_double_constant();
   795   return TypeInt::make( SharedRuntime::d2i( td->getd() ) );
   796 }
   798 //------------------------------Ideal------------------------------------------
   799 // If converting to an int type, skip any rounding nodes
   800 Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
   801   if( in(1)->Opcode() == Op_RoundDouble )
   802     set_req(1,in(1)->in(1));
   803   return NULL;
   804 }
   806 //------------------------------Identity---------------------------------------
   807 // Int's can be converted to doubles with no loss of bits.  Hence
   808 // converting an integer to a double and back to an integer is a NOP.
   809 Node *ConvD2INode::Identity(PhaseTransform *phase) {
   810   return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;
   811 }
   813 //=============================================================================
   814 //------------------------------Value------------------------------------------
   815 const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {
   816   const Type *t = phase->type( in(1) );
   817   if( t == Type::TOP ) return Type::TOP;
   818   if( t == Type::DOUBLE ) return TypeLong::LONG;
   819   const TypeD *td = t->is_double_constant();
   820   return TypeLong::make( SharedRuntime::d2l( td->getd() ) );
   821 }
   823 //------------------------------Identity---------------------------------------
   824 Node *ConvD2LNode::Identity(PhaseTransform *phase) {
   825   // Remove ConvD2L->ConvL2D->ConvD2L sequences.
   826   if( in(1)       ->Opcode() == Op_ConvL2D &&
   827       in(1)->in(1)->Opcode() == Op_ConvD2L )
   828     return in(1)->in(1);
   829   return this;
   830 }
   832 //------------------------------Ideal------------------------------------------
   833 // If converting to an int type, skip any rounding nodes
   834 Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   835   if( in(1)->Opcode() == Op_RoundDouble )
   836     set_req(1,in(1)->in(1));
   837   return NULL;
   838 }
   840 //=============================================================================
   841 //------------------------------Value------------------------------------------
   842 const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {
   843   const Type *t = phase->type( in(1) );
   844   if( t == Type::TOP ) return Type::TOP;
   845   if( t == Type::FLOAT ) return Type::DOUBLE;
   846   const TypeF *tf = t->is_float_constant();
   847   return TypeD::make( (double)tf->getf() );
   848 }
   850 //=============================================================================
   851 //------------------------------Value------------------------------------------
   852 const Type *ConvF2INode::Value( PhaseTransform *phase ) const {
   853   const Type *t = phase->type( in(1) );
   854   if( t == Type::TOP )       return Type::TOP;
   855   if( t == Type::FLOAT ) return TypeInt::INT;
   856   const TypeF *tf = t->is_float_constant();
   857   return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );
   858 }
   860 //------------------------------Identity---------------------------------------
   861 Node *ConvF2INode::Identity(PhaseTransform *phase) {
   862   // Remove ConvF2I->ConvI2F->ConvF2I sequences.
   863   if( in(1)       ->Opcode() == Op_ConvI2F &&
   864       in(1)->in(1)->Opcode() == Op_ConvF2I )
   865     return in(1)->in(1);
   866   return this;
   867 }
   869 //------------------------------Ideal------------------------------------------
   870 // If converting to an int type, skip any rounding nodes
   871 Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
   872   if( in(1)->Opcode() == Op_RoundFloat )
   873     set_req(1,in(1)->in(1));
   874   return NULL;
   875 }
   877 //=============================================================================
   878 //------------------------------Value------------------------------------------
   879 const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {
   880   const Type *t = phase->type( in(1) );
   881   if( t == Type::TOP )       return Type::TOP;
   882   if( t == Type::FLOAT ) return TypeLong::LONG;
   883   const TypeF *tf = t->is_float_constant();
   884   return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );
   885 }
   887 //------------------------------Identity---------------------------------------
   888 Node *ConvF2LNode::Identity(PhaseTransform *phase) {
   889   // Remove ConvF2L->ConvL2F->ConvF2L sequences.
   890   if( in(1)       ->Opcode() == Op_ConvL2F &&
   891       in(1)->in(1)->Opcode() == Op_ConvF2L )
   892     return in(1)->in(1);
   893   return this;
   894 }
   896 //------------------------------Ideal------------------------------------------
   897 // If converting to an int type, skip any rounding nodes
   898 Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   899   if( in(1)->Opcode() == Op_RoundFloat )
   900     set_req(1,in(1)->in(1));
   901   return NULL;
   902 }
   904 //=============================================================================
   905 //------------------------------Value------------------------------------------
   906 const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {
   907   const Type *t = phase->type( in(1) );
   908   if( t == Type::TOP ) return Type::TOP;
   909   const TypeInt *ti = t->is_int();
   910   if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );
   911   return bottom_type();
   912 }
   914 //=============================================================================
   915 //------------------------------Value------------------------------------------
   916 const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {
   917   const Type *t = phase->type( in(1) );
   918   if( t == Type::TOP ) return Type::TOP;
   919   const TypeInt *ti = t->is_int();
   920   if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );
   921   return bottom_type();
   922 }
   924 //------------------------------Identity---------------------------------------
   925 Node *ConvI2FNode::Identity(PhaseTransform *phase) {
   926   // Remove ConvI2F->ConvF2I->ConvI2F sequences.
   927   if( in(1)       ->Opcode() == Op_ConvF2I &&
   928       in(1)->in(1)->Opcode() == Op_ConvI2F )
   929     return in(1)->in(1);
   930   return this;
   931 }
   933 //=============================================================================
   934 //------------------------------Value------------------------------------------
   935 const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {
   936   const Type *t = phase->type( in(1) );
   937   if( t == Type::TOP ) return Type::TOP;
   938   const TypeInt *ti = t->is_int();
   939   const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);
   940   // Join my declared type against my incoming type.
   941   tl = tl->filter(_type);
   942   return tl;
   943 }
   945 #ifdef _LP64
   946 static inline bool long_ranges_overlap(jlong lo1, jlong hi1,
   947                                        jlong lo2, jlong hi2) {
   948   // Two ranges overlap iff one range's low point falls in the other range.
   949   return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);
   950 }
   951 #endif
   953 //------------------------------Ideal------------------------------------------
   954 Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
   955   const TypeLong* this_type = this->type()->is_long();
   956   Node* this_changed = NULL;
   958   // If _major_progress, then more loop optimizations follow.  Do NOT
   959   // remove this node's type assertion until no more loop ops can happen.
   960   // The progress bit is set in the major loop optimizations THEN comes the
   961   // call to IterGVN and any chance of hitting this code.  Cf. Opaque1Node.
   962   if (can_reshape && !phase->C->major_progress()) {
   963     const TypeInt* in_type = phase->type(in(1))->isa_int();
   964     if (in_type != NULL && this_type != NULL &&
   965         (in_type->_lo != this_type->_lo ||
   966          in_type->_hi != this_type->_hi)) {
   967       // Although this WORSENS the type, it increases GVN opportunities,
   968       // because I2L nodes with the same input will common up, regardless
   969       // of slightly differing type assertions.  Such slight differences
   970       // arise routinely as a result of loop unrolling, so this is a
   971       // post-unrolling graph cleanup.  Choose a type which depends only
   972       // on my input.  (Exception:  Keep a range assertion of >=0 or <0.)
   973       jlong lo1 = this_type->_lo;
   974       jlong hi1 = this_type->_hi;
   975       int   w1  = this_type->_widen;
   976       if (lo1 != (jint)lo1 ||
   977           hi1 != (jint)hi1 ||
   978           lo1 > hi1) {
   979         // Overflow leads to wraparound, wraparound leads to range saturation.
   980         lo1 = min_jint; hi1 = max_jint;
   981       } else if (lo1 >= 0) {
   982         // Keep a range assertion of >=0.
   983         lo1 = 0;        hi1 = max_jint;
   984       } else if (hi1 < 0) {
   985         // Keep a range assertion of <0.
   986         lo1 = min_jint; hi1 = -1;
   987       } else {
   988         lo1 = min_jint; hi1 = max_jint;
   989       }
   990       const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
   991                                              MIN2((jlong)in_type->_hi, hi1),
   992                                              MAX2((int)in_type->_widen, w1));
   993       if (wtype != type()) {
   994         set_type(wtype);
   995         // Note: this_type still has old type value, for the logic below.
   996         this_changed = this;
   997       }
   998     }
   999   }
  1001 #ifdef _LP64
  1002   // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) or
  1003   // ConvI2L(CastII(AddI(x, y))) to AddL(ConvI2L(CastII(x)), ConvI2L(CastII(y))),
  1004   // but only if x and y have subranges that cannot cause 32-bit overflow,
  1005   // under the assumption that x+y is in my own subrange this->type().
  1007   // This assumption is based on a constraint (i.e., type assertion)
  1008   // established in Parse::array_addressing or perhaps elsewhere.
  1009   // This constraint has been adjoined to the "natural" type of
  1010   // the incoming argument in(0).  We know (because of runtime
  1011   // checks) - that the result value I2L(x+y) is in the joined range.
  1012   // Hence we can restrict the incoming terms (x, y) to values such
  1013   // that their sum also lands in that range.
  1015   // This optimization is useful only on 64-bit systems, where we hope
  1016   // the addition will end up subsumed in an addressing mode.
  1017   // It is necessary to do this when optimizing an unrolled array
  1018   // copy loop such as x[i++] = y[i++].
  1020   // On 32-bit systems, it's better to perform as much 32-bit math as
  1021   // possible before the I2L conversion, because 32-bit math is cheaper.
  1022   // There's no common reason to "leak" a constant offset through the I2L.
  1023   // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
  1025   Node* z = in(1);
  1026   int op = z->Opcode();
  1027   Node* ctrl = NULL;
  1028   if (op == Op_CastII && z->as_CastII()->has_range_check()) {
  1029     // Skip CastII node but save control dependency
  1030     ctrl = z->in(0);
  1031     z = z->in(1);
  1032     op = z->Opcode();
  1034   if (op == Op_AddI || op == Op_SubI) {
  1035     Node* x = z->in(1);
  1036     Node* y = z->in(2);
  1037     assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
  1038     if (phase->type(x) == Type::TOP)  return this_changed;
  1039     if (phase->type(y) == Type::TOP)  return this_changed;
  1040     const TypeInt*  tx = phase->type(x)->is_int();
  1041     const TypeInt*  ty = phase->type(y)->is_int();
  1042     const TypeLong* tz = this_type;
  1043     jlong xlo = tx->_lo;
  1044     jlong xhi = tx->_hi;
  1045     jlong ylo = ty->_lo;
  1046     jlong yhi = ty->_hi;
  1047     jlong zlo = tz->_lo;
  1048     jlong zhi = tz->_hi;
  1049     jlong vbit = CONST64(1) << BitsPerInt;
  1050     int widen =  MAX2(tx->_widen, ty->_widen);
  1051     if (op == Op_SubI) {
  1052       jlong ylo0 = ylo;
  1053       ylo = -yhi;
  1054       yhi = -ylo0;
  1056     // See if x+y can cause positive overflow into z+2**32
  1057     if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {
  1058       return this_changed;
  1060     // See if x+y can cause negative overflow into z-2**32
  1061     if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {
  1062       return this_changed;
  1064     // Now it's always safe to assume x+y does not overflow.
  1065     // This is true even if some pairs x,y might cause overflow, as long
  1066     // as that overflow value cannot fall into [zlo,zhi].
  1068     // Confident that the arithmetic is "as if infinite precision",
  1069     // we can now use z's range to put constraints on those of x and y.
  1070     // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a
  1071     // more "restricted" range by intersecting [xlo,xhi] with the
  1072     // range obtained by subtracting y's range from the asserted range
  1073     // of the I2L conversion.  Here's the interval arithmetic algebra:
  1074     //    x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
  1075     //    => x in [zlo-yhi, zhi-ylo]
  1076     //    => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
  1077     //    => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
  1078     jlong rxlo = MAX2(xlo, zlo - yhi);
  1079     jlong rxhi = MIN2(xhi, zhi - ylo);
  1080     // And similarly, x changing place with y:
  1081     jlong rylo = MAX2(ylo, zlo - xhi);
  1082     jlong ryhi = MIN2(yhi, zhi - xlo);
  1083     if (rxlo > rxhi || rylo > ryhi) {
  1084       return this_changed;  // x or y is dying; don't mess w/ it
  1086     if (op == Op_SubI) {
  1087       jlong rylo0 = rylo;
  1088       rylo = -ryhi;
  1089       ryhi = -rylo0;
  1091     assert(rxlo == (int)rxlo && rxhi == (int)rxhi, "x should not overflow");
  1092     assert(rylo == (int)rylo && ryhi == (int)ryhi, "y should not overflow");
  1093     Node* cx = phase->C->constrained_convI2L(phase, x, TypeInt::make(rxlo, rxhi, widen), ctrl);
  1094     Node* cy = phase->C->constrained_convI2L(phase, y, TypeInt::make(rylo, ryhi, widen), ctrl);
  1095     switch (op) {
  1096     case Op_AddI:  return new (phase->C) AddLNode(cx, cy);
  1097     case Op_SubI:  return new (phase->C) SubLNode(cx, cy);
  1098     default:       ShouldNotReachHere();
  1101 #endif //_LP64
  1103   return this_changed;
  1106 //=============================================================================
  1107 //------------------------------Value------------------------------------------
  1108 const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
  1109   const Type *t = phase->type( in(1) );
  1110   if( t == Type::TOP ) return Type::TOP;
  1111   const TypeLong *tl = t->is_long();
  1112   if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
  1113   return bottom_type();
  1116 //=============================================================================
  1117 //------------------------------Value------------------------------------------
  1118 const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {
  1119   const Type *t = phase->type( in(1) );
  1120   if( t == Type::TOP ) return Type::TOP;
  1121   const TypeLong *tl = t->is_long();
  1122   if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );
  1123   return bottom_type();
  1126 //=============================================================================
  1127 //----------------------------Identity-----------------------------------------
  1128 Node *ConvL2INode::Identity( PhaseTransform *phase ) {
  1129   // Convert L2I(I2L(x)) => x
  1130   if (in(1)->Opcode() == Op_ConvI2L)  return in(1)->in(1);
  1131   return this;
  1134 //------------------------------Value------------------------------------------
  1135 const Type *ConvL2INode::Value( PhaseTransform *phase ) const {
  1136   const Type *t = phase->type( in(1) );
  1137   if( t == Type::TOP ) return Type::TOP;
  1138   const TypeLong *tl = t->is_long();
  1139   if (tl->is_con())
  1140     // Easy case.
  1141     return TypeInt::make((jint)tl->get_con());
  1142   return bottom_type();
  1145 //------------------------------Ideal------------------------------------------
  1146 // Return a node which is more "ideal" than the current node.
  1147 // Blow off prior masking to int
  1148 Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
  1149   Node *andl = in(1);
  1150   uint andl_op = andl->Opcode();
  1151   if( andl_op == Op_AndL ) {
  1152     // Blow off prior masking to int
  1153     if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {
  1154       set_req(1,andl->in(1));
  1155       return this;
  1159   // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
  1160   // This replaces an 'AddL' with an 'AddI'.
  1161   if( andl_op == Op_AddL ) {
  1162     // Don't do this for nodes which have more than one user since
  1163     // we'll end up computing the long add anyway.
  1164     if (andl->outcnt() > 1) return NULL;
  1166     Node* x = andl->in(1);
  1167     Node* y = andl->in(2);
  1168     assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );
  1169     if (phase->type(x) == Type::TOP)  return NULL;
  1170     if (phase->type(y) == Type::TOP)  return NULL;
  1171     Node *add1 = phase->transform(new (phase->C) ConvL2INode(x));
  1172     Node *add2 = phase->transform(new (phase->C) ConvL2INode(y));
  1173     return new (phase->C) AddINode(add1,add2);
  1176   // Disable optimization: LoadL->ConvL2I ==> LoadI.
  1177   // It causes problems (sizes of Load and Store nodes do not match)
  1178   // in objects initialization code and Escape Analysis.
  1179   return NULL;
  1182 //=============================================================================
  1183 //------------------------------Value------------------------------------------
  1184 const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
  1185   const Type* t = phase->type(in(1));
  1186   if (t == Type::TOP) return Type::TOP;
  1187   if (t->base() == Type_X && t->singleton()) {
  1188     uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
  1189     if (bits == 0)   return TypePtr::NULL_PTR;
  1190     return TypeRawPtr::make((address) bits);
  1192   return CastX2PNode::bottom_type();
  1195 //------------------------------Idealize---------------------------------------
  1196 static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
  1197   if (t == Type::TOP)  return false;
  1198   const TypeX* tl = t->is_intptr_t();
  1199   jint lo = min_jint;
  1200   jint hi = max_jint;
  1201   if (but_not_min_int)  ++lo;  // caller wants to negate the value w/o overflow
  1202   return (tl->_lo >= lo) && (tl->_hi <= hi);
  1205 static inline Node* addP_of_X2P(PhaseGVN *phase,
  1206                                 Node* base,
  1207                                 Node* dispX,
  1208                                 bool negate = false) {
  1209   if (negate) {
  1210     dispX = new (phase->C) SubXNode(phase->MakeConX(0), phase->transform(dispX));
  1212   return new (phase->C) AddPNode(phase->C->top(),
  1213                           phase->transform(new (phase->C) CastX2PNode(base)),
  1214                           phase->transform(dispX));
  1217 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
  1218   // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
  1219   int op = in(1)->Opcode();
  1220   Node* x;
  1221   Node* y;
  1222   switch (op) {
  1223   case Op_SubX:
  1224     x = in(1)->in(1);
  1225     // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
  1226     if (phase->find_intptr_t_con(x, -1) == 0)
  1227       break;
  1228     y = in(1)->in(2);
  1229     if (fits_in_int(phase->type(y), true)) {
  1230       return addP_of_X2P(phase, x, y, true);
  1232     break;
  1233   case Op_AddX:
  1234     x = in(1)->in(1);
  1235     y = in(1)->in(2);
  1236     if (fits_in_int(phase->type(y))) {
  1237       return addP_of_X2P(phase, x, y);
  1239     if (fits_in_int(phase->type(x))) {
  1240       return addP_of_X2P(phase, y, x);
  1242     break;
  1244   return NULL;
  1247 //------------------------------Identity---------------------------------------
  1248 Node *CastX2PNode::Identity( PhaseTransform *phase ) {
  1249   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
  1250   return this;
  1253 //=============================================================================
  1254 //------------------------------Value------------------------------------------
  1255 const Type *CastP2XNode::Value( PhaseTransform *phase ) const {
  1256   const Type* t = phase->type(in(1));
  1257   if (t == Type::TOP) return Type::TOP;
  1258   if (t->base() == Type::RawPtr && t->singleton()) {
  1259     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
  1260     return TypeX::make(bits);
  1262   return CastP2XNode::bottom_type();
  1265 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
  1266   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
  1269 //------------------------------Identity---------------------------------------
  1270 Node *CastP2XNode::Identity( PhaseTransform *phase ) {
  1271   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
  1272   return this;
  1276 //=============================================================================
  1277 //------------------------------Identity---------------------------------------
  1278 // Remove redundant roundings
  1279 Node *RoundFloatNode::Identity( PhaseTransform *phase ) {
  1280   assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
  1281   // Do not round constants
  1282   if (phase->type(in(1))->base() == Type::FloatCon)  return in(1);
  1283   int op = in(1)->Opcode();
  1284   // Redundant rounding
  1285   if( op == Op_RoundFloat ) return in(1);
  1286   // Already rounded
  1287   if( op == Op_Parm ) return in(1);
  1288   if( op == Op_LoadF ) return in(1);
  1289   return this;
  1292 //------------------------------Value------------------------------------------
  1293 const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {
  1294   return phase->type( in(1) );
  1297 //=============================================================================
  1298 //------------------------------Identity---------------------------------------
  1299 // Remove redundant roundings.  Incoming arguments are already rounded.
  1300 Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {
  1301   assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
  1302   // Do not round constants
  1303   if (phase->type(in(1))->base() == Type::DoubleCon)  return in(1);
  1304   int op = in(1)->Opcode();
  1305   // Redundant rounding
  1306   if( op == Op_RoundDouble ) return in(1);
  1307   // Already rounded
  1308   if( op == Op_Parm ) return in(1);
  1309   if( op == Op_LoadD ) return in(1);
  1310   if( op == Op_ConvF2D ) return in(1);
  1311   if( op == Op_ConvI2D ) return in(1);
  1312   return this;
  1315 //------------------------------Value------------------------------------------
  1316 const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {
  1317   return phase->type( in(1) );
  1321 //=============================================================================
  1322 // Do not allow value-numbering
  1323 uint Opaque1Node::hash() const { return NO_HASH; }
  1324 uint Opaque1Node::cmp( const Node &n ) const {
  1325   return (&n == this);          // Always fail except on self
  1328 //------------------------------Identity---------------------------------------
  1329 // If _major_progress, then more loop optimizations follow.  Do NOT remove
  1330 // the opaque Node until no more loop ops can happen.  Note the timing of
  1331 // _major_progress; it's set in the major loop optimizations THEN comes the
  1332 // call to IterGVN and any chance of hitting this code.  Hence there's no
  1333 // phase-ordering problem with stripping Opaque1 in IGVN followed by some
  1334 // more loop optimizations that require it.
  1335 Node *Opaque1Node::Identity( PhaseTransform *phase ) {
  1336   return phase->C->major_progress() ? this : in(1);
  1339 //=============================================================================
  1340 // A node to prevent unwanted optimizations.  Allows constant folding.  Stops
  1341 // value-numbering, most Ideal calls or Identity functions.  This Node is
  1342 // specifically designed to prevent the pre-increment value of a loop trip
  1343 // counter from being live out of the bottom of the loop (hence causing the
  1344 // pre- and post-increment values both being live and thus requiring an extra
  1345 // temp register and an extra move).  If we "accidentally" optimize through
  1346 // this kind of a Node, we'll get slightly pessimal, but correct, code.  Thus
  1347 // it's OK to be slightly sloppy on optimizations here.
  1349 // Do not allow value-numbering
  1350 uint Opaque2Node::hash() const { return NO_HASH; }
  1351 uint Opaque2Node::cmp( const Node &n ) const {
  1352   return (&n == this);          // Always fail except on self
  1355 //=============================================================================
  1357 uint ProfileBooleanNode::hash() const { return NO_HASH; }
  1358 uint ProfileBooleanNode::cmp( const Node &n ) const {
  1359   return (&n == this);
  1362 Node *ProfileBooleanNode::Ideal(PhaseGVN *phase, bool can_reshape) {
  1363   if (can_reshape && _delay_removal) {
  1364     _delay_removal = false;
  1365     return this;
  1366   } else {
  1367     return NULL;
  1371 Node *ProfileBooleanNode::Identity( PhaseTransform *phase ) {
  1372   if (_delay_removal) {
  1373     return this;
  1374   } else {
  1375     assert(_consumed, "profile should be consumed before elimination");
  1376     return in(1);
  1380 //------------------------------Value------------------------------------------
  1381 const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {
  1382   const Type *t = phase->type( in(1) );
  1383   if( t == Type::TOP ) return Type::TOP;
  1384   const TypeLong *tl = t->is_long();
  1385   if( !tl->is_con() ) return bottom_type();
  1386   JavaValue v;
  1387   v.set_jlong(tl->get_con());
  1388   return TypeD::make( v.get_jdouble() );
  1391 //------------------------------Value------------------------------------------
  1392 const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {
  1393   const Type *t = phase->type( in(1) );
  1394   if( t == Type::TOP ) return Type::TOP;
  1395   const TypeInt *ti = t->is_int();
  1396   if( !ti->is_con() )   return bottom_type();
  1397   JavaValue v;
  1398   v.set_jint(ti->get_con());
  1399   return TypeF::make( v.get_jfloat() );
  1402 //------------------------------Value------------------------------------------
  1403 const Type *MoveF2INode::Value( PhaseTransform *phase ) const {
  1404   const Type *t = phase->type( in(1) );
  1405   if( t == Type::TOP )       return Type::TOP;
  1406   if( t == Type::FLOAT ) return TypeInt::INT;
  1407   const TypeF *tf = t->is_float_constant();
  1408   JavaValue v;
  1409   v.set_jfloat(tf->getf());
  1410   return TypeInt::make( v.get_jint() );
  1413 //------------------------------Value------------------------------------------
  1414 const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {
  1415   const Type *t = phase->type( in(1) );
  1416   if( t == Type::TOP ) return Type::TOP;
  1417   if( t == Type::DOUBLE ) return TypeLong::LONG;
  1418   const TypeD *td = t->is_double_constant();
  1419   JavaValue v;
  1420   v.set_jdouble(td->getd());
  1421   return TypeLong::make( v.get_jlong() );
  1424 //------------------------------Value------------------------------------------
  1425 const Type* CountLeadingZerosINode::Value(PhaseTransform* phase) const {
  1426   const Type* t = phase->type(in(1));
  1427   if (t == Type::TOP) return Type::TOP;
  1428   const TypeInt* ti = t->isa_int();
  1429   if (ti && ti->is_con()) {
  1430     jint i = ti->get_con();
  1431     // HD, Figure 5-6
  1432     if (i == 0)
  1433       return TypeInt::make(BitsPerInt);
  1434     int n = 1;
  1435     unsigned int x = i;
  1436     if (x >> 16 == 0) { n += 16; x <<= 16; }
  1437     if (x >> 24 == 0) { n +=  8; x <<=  8; }
  1438     if (x >> 28 == 0) { n +=  4; x <<=  4; }
  1439     if (x >> 30 == 0) { n +=  2; x <<=  2; }
  1440     n -= x >> 31;
  1441     return TypeInt::make(n);
  1443   return TypeInt::INT;
  1446 //------------------------------Value------------------------------------------
  1447 const Type* CountLeadingZerosLNode::Value(PhaseTransform* phase) const {
  1448   const Type* t = phase->type(in(1));
  1449   if (t == Type::TOP) return Type::TOP;
  1450   const TypeLong* tl = t->isa_long();
  1451   if (tl && tl->is_con()) {
  1452     jlong l = tl->get_con();
  1453     // HD, Figure 5-6
  1454     if (l == 0)
  1455       return TypeInt::make(BitsPerLong);
  1456     int n = 1;
  1457     unsigned int x = (((julong) l) >> 32);
  1458     if (x == 0) { n += 32; x = (int) l; }
  1459     if (x >> 16 == 0) { n += 16; x <<= 16; }
  1460     if (x >> 24 == 0) { n +=  8; x <<=  8; }
  1461     if (x >> 28 == 0) { n +=  4; x <<=  4; }
  1462     if (x >> 30 == 0) { n +=  2; x <<=  2; }
  1463     n -= x >> 31;
  1464     return TypeInt::make(n);
  1466   return TypeInt::INT;
  1469 //------------------------------Value------------------------------------------
  1470 const Type* CountTrailingZerosINode::Value(PhaseTransform* phase) const {
  1471   const Type* t = phase->type(in(1));
  1472   if (t == Type::TOP) return Type::TOP;
  1473   const TypeInt* ti = t->isa_int();
  1474   if (ti && ti->is_con()) {
  1475     jint i = ti->get_con();
  1476     // HD, Figure 5-14
  1477     int y;
  1478     if (i == 0)
  1479       return TypeInt::make(BitsPerInt);
  1480     int n = 31;
  1481     y = i << 16; if (y != 0) { n = n - 16; i = y; }
  1482     y = i <<  8; if (y != 0) { n = n -  8; i = y; }
  1483     y = i <<  4; if (y != 0) { n = n -  4; i = y; }
  1484     y = i <<  2; if (y != 0) { n = n -  2; i = y; }
  1485     y = i <<  1; if (y != 0) { n = n -  1; }
  1486     return TypeInt::make(n);
  1488   return TypeInt::INT;
  1491 //------------------------------Value------------------------------------------
  1492 const Type* CountTrailingZerosLNode::Value(PhaseTransform* phase) const {
  1493   const Type* t = phase->type(in(1));
  1494   if (t == Type::TOP) return Type::TOP;
  1495   const TypeLong* tl = t->isa_long();
  1496   if (tl && tl->is_con()) {
  1497     jlong l = tl->get_con();
  1498     // HD, Figure 5-14
  1499     int x, y;
  1500     if (l == 0)
  1501       return TypeInt::make(BitsPerLong);
  1502     int n = 63;
  1503     y = (int) l; if (y != 0) { n = n - 32; x = y; } else x = (((julong) l) >> 32);
  1504     y = x << 16; if (y != 0) { n = n - 16; x = y; }
  1505     y = x <<  8; if (y != 0) { n = n -  8; x = y; }
  1506     y = x <<  4; if (y != 0) { n = n -  4; x = y; }
  1507     y = x <<  2; if (y != 0) { n = n -  2; x = y; }
  1508     y = x <<  1; if (y != 0) { n = n -  1; }
  1509     return TypeInt::make(n);
  1511   return TypeInt::INT;

mercurial