< prev index next >

src/share/vm/opto/subnode.cpp

Print this page




  29 #include "opto/callnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/loopnode.hpp"
  32 #include "opto/matcher.hpp"
  33 #include "opto/movenode.hpp"
  34 #include "opto/mulnode.hpp"
  35 #include "opto/opcodes.hpp"
  36 #include "opto/phaseX.hpp"
  37 #include "opto/subnode.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 
  40 // Portions of code courtesy of Clifford Click
  41 
  42 // Optimization - Graph Style
  43 
  44 #include "math.h"
  45 
  46 //=============================================================================
  47 //------------------------------Identity---------------------------------------
  48 // If right input is a constant 0, return the left input.
  49 Node *SubNode::Identity( PhaseTransform *phase ) {
  50   assert(in(1) != this, "Must already have called Value");
  51   assert(in(2) != this, "Must already have called Value");
  52 
  53   // Remove double negation
  54   const Type *zero = add_id();
  55   if( phase->type( in(1) )->higher_equal( zero ) &&
  56       in(2)->Opcode() == Opcode() &&
  57       phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
  58     return in(2)->in(2);
  59   }
  60 
  61   // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y
  62   if( in(1)->Opcode() == Op_AddI ) {
  63     if( phase->eqv(in(1)->in(2),in(2)) )
  64       return in(1)->in(1);
  65     if (phase->eqv(in(1)->in(1),in(2)))
  66       return in(1)->in(2);
  67 
  68     // Also catch: "(X + Opaque2(Y)) - Y".  In this case, 'Y' is a loop-varying
  69     // trip counter and X is likely to be loop-invariant (that's how O2 Nodes


  83 const Type* SubNode::Value_common(PhaseTransform *phase) const {
  84   const Node* in1 = in(1);
  85   const Node* in2 = in(2);
  86   // Either input is TOP ==> the result is TOP
  87   const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
  88   if( t1 == Type::TOP ) return Type::TOP;
  89   const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
  90   if( t2 == Type::TOP ) return Type::TOP;
  91 
  92   // Not correct for SubFnode and AddFNode (must check for infinity)
  93   // Equal?  Subtract is zero
  94   if (in1->eqv_uncast(in2))  return add_id();
  95 
  96   // Either input is BOTTOM ==> the result is the local BOTTOM
  97   if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
  98     return bottom_type();
  99 
 100   return NULL;
 101 }
 102 
 103 const Type* SubNode::Value(PhaseTransform *phase) const {
 104   const Type* t = Value_common(phase);
 105   if (t != NULL) {
 106     return t;
 107   }
 108   const Type* t1 = phase->type(in(1));
 109   const Type* t2 = phase->type(in(2));
 110   return sub(t1,t2);            // Local flavor of type subtraction
 111 
 112 }
 113 
 114 //=============================================================================
 115 
 116 //------------------------------Helper function--------------------------------
 117 static bool ok_to_convert(Node* inc, Node* iv) {
 118     // Do not collapse (x+c0)-y if "+" is a loop increment, because the
 119     // "-" is loop invariant and collapsing extends the live-range of "x"
 120     // to overlap with the "+", forcing another register to be used in
 121     // the loop.
 122     // This test will be clearer with '&&' (apply DeMorgan's rule)
 123     // but I like the early cutouts that happen here.


 361 const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
 362   const TypeLong *r0 = t1->is_long(); // Handy access
 363   const TypeLong *r1 = t2->is_long();
 364   jlong lo = java_subtract(r0->_lo, r1->_hi);
 365   jlong hi = java_subtract(r0->_hi, r1->_lo);
 366 
 367   // We next check for 32-bit overflow.
 368   // If that happens, we just assume all integers are possible.
 369   if( (((r0->_lo ^ r1->_hi) >= 0) ||    // lo ends have same signs OR
 370        ((r0->_lo ^      lo) >= 0)) &&   // lo results have same signs AND
 371       (((r0->_hi ^ r1->_lo) >= 0) ||    // hi ends have same signs OR
 372        ((r0->_hi ^      hi) >= 0)) )    // hi results have same signs
 373     return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
 374   else                          // Overflow; assume all integers
 375     return TypeLong::LONG;
 376 }
 377 
 378 //=============================================================================
 379 //------------------------------Value------------------------------------------
 380 // A subtract node differences its two inputs.
 381 const Type *SubFPNode::Value( PhaseTransform *phase ) const {
 382   const Node* in1 = in(1);
 383   const Node* in2 = in(2);
 384   // Either input is TOP ==> the result is TOP
 385   const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
 386   if( t1 == Type::TOP ) return Type::TOP;
 387   const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
 388   if( t2 == Type::TOP ) return Type::TOP;
 389 
 390   // if both operands are infinity of same sign, the result is NaN; do
 391   // not replace with zero
 392   if( (t1->is_finite() && t2->is_finite()) ) {
 393     if( phase->eqv(in1, in2) ) return add_id();
 394   }
 395 
 396   // Either input is BOTTOM ==> the result is the local BOTTOM
 397   const Type *bot = bottom_type();
 398   if( (t1 == bot) || (t2 == bot) ||
 399       (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
 400     return bot;
 401 


 477   // no folding if one of operands is infinity or NaN, do not do constant folding
 478   if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) {
 479     return TypeD::make( t1->getd() - t2->getd() );
 480   }
 481   else if( g_isnan(t1->getd()) ) {
 482     return t1;
 483   }
 484   else if( g_isnan(t2->getd()) ) {
 485     return t2;
 486   }
 487   else {
 488     return Type::DOUBLE;
 489   }
 490 }
 491 
 492 //=============================================================================
 493 //------------------------------Idealize---------------------------------------
 494 // Unlike SubNodes, compare must still flatten return value to the
 495 // range -1, 0, 1.
 496 // And optimizations like those for (X + Y) - X fail if overflow happens.
 497 Node *CmpNode::Identity( PhaseTransform *phase ) {
 498   return this;
 499 }
 500 
 501 #ifndef PRODUCT
 502 //----------------------------related------------------------------------------
 503 // Related nodes of comparison nodes include all data inputs (until hitting a
 504 // control boundary) as well as all outputs until and including control nodes
 505 // as well as their projections. In compact mode, data inputs till depth 1 and
 506 // all outputs till depth 1 are considered.
 507 void CmpNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
 508   if (compact) {
 509     this->collect_nodes(in_rel, 1, false, true);
 510     this->collect_nodes(out_rel, -1, false, false);
 511   } else {
 512     this->collect_nodes_in_all_data(in_rel, false);
 513     this->collect_nodes_out_all_ctrl_boundary(out_rel);
 514     // Now, find all control nodes in out_rel, and include their projections
 515     // and projection targets (if any) in the result.
 516     GrowableArray<Node*> proj(Compile::current()->unique());
 517     for (GrowableArrayIterator<Node*> it = out_rel->begin(); it != out_rel->end(); ++it) {


 594     } else if (lo0 >= hi1) {
 595       return TypeInt::CC_GE;
 596     } else if (hi0 <= lo1) {
 597       // Check for special case in Hashtable::get.  (See below.)
 598       if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
 599         return TypeInt::CC_LT;
 600       return TypeInt::CC_LE;
 601     }
 602   }
 603   // Check for special case in Hashtable::get - the hash index is
 604   // mod'ed to the table size so the following range check is useless.
 605   // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
 606   // to be positive.
 607   // (This is a gross hack, since the sub method never
 608   // looks at the structure of the node in any other case.)
 609   if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
 610     return TypeInt::CC_LT;
 611   return TypeInt::CC;                   // else use worst case results
 612 }
 613 
 614 const Type* CmpUNode::Value(PhaseTransform *phase) const {
 615   const Type* t = SubNode::Value_common(phase);
 616   if (t != NULL) {
 617     return t;
 618   }
 619   const Node* in1 = in(1);
 620   const Node* in2 = in(2);
 621   const Type* t1 = phase->type(in1);
 622   const Type* t2 = phase->type(in2);
 623   assert(t1->isa_int(), "CmpU has only Int type inputs");
 624   if (t2 == TypeInt::INT) { // Compare to bottom?
 625     return bottom_type();
 626   }
 627   uint in1_op = in1->Opcode();
 628   if (in1_op == Op_AddI || in1_op == Op_SubI) {
 629     // The problem rise when result of AddI(SubI) may overflow
 630     // signed integer value. Let say the input type is
 631     // [256, maxint] then +128 will create 2 ranges due to
 632     // overflow: [minint, minint+127] and [384, maxint].
 633     // But C2 type system keep only 1 type range and as result
 634     // it use general [minint, maxint] for this case which we


1036     intptr_t bits0 = r0->get_con();
1037     if( r1->singleton() )
1038       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1039     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1040   } else if( r1->singleton() ) {
1041     intptr_t bits1 = r1->get_con();
1042     return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1043   } else
1044     return TypeInt::CC;
1045 }
1046 
1047 //------------------------------Ideal------------------------------------------
1048 Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
1049   return NULL;
1050 }
1051 
1052 //=============================================================================
1053 //------------------------------Value------------------------------------------
1054 // Simplify an CmpF (compare 2 floats ) node, based on local information.
1055 // If both inputs are constants, compare them.
1056 const Type *CmpFNode::Value( PhaseTransform *phase ) const {
1057   const Node* in1 = in(1);
1058   const Node* in2 = in(2);
1059   // Either input is TOP ==> the result is TOP
1060   const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
1061   if( t1 == Type::TOP ) return Type::TOP;
1062   const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
1063   if( t2 == Type::TOP ) return Type::TOP;
1064 
1065   // Not constants?  Don't know squat - even if they are the same
1066   // value!  If they are NaN's they compare to LT instead of EQ.
1067   const TypeF *tf1 = t1->isa_float_constant();
1068   const TypeF *tf2 = t2->isa_float_constant();
1069   if( !tf1 || !tf2 ) return TypeInt::CC;
1070 
1071   // This implements the Java bytecode fcmpl, so unordered returns -1.
1072   if( tf1->is_nan() || tf2->is_nan() )
1073     return TypeInt::CC_LT;
1074 
1075   if( tf1->_f < tf2->_f ) return TypeInt::CC_LT;
1076   if( tf1->_f > tf2->_f ) return TypeInt::CC_GT;
1077   assert( tf1->_f == tf2->_f, "do not understand FP behavior" );
1078   return TypeInt::CC_EQ;
1079 }
1080 
1081 
1082 //=============================================================================
1083 //------------------------------Value------------------------------------------
1084 // Simplify an CmpD (compare 2 doubles ) node, based on local information.
1085 // If both inputs are constants, compare them.
1086 const Type *CmpDNode::Value( PhaseTransform *phase ) const {
1087   const Node* in1 = in(1);
1088   const Node* in2 = in(2);
1089   // Either input is TOP ==> the result is TOP
1090   const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
1091   if( t1 == Type::TOP ) return Type::TOP;
1092   const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
1093   if( t2 == Type::TOP ) return Type::TOP;
1094 
1095   // Not constants?  Don't know squat - even if they are the same
1096   // value!  If they are NaN's they compare to LT instead of EQ.
1097   const TypeD *td1 = t1->isa_double_constant();
1098   const TypeD *td2 = t2->isa_double_constant();
1099   if( !td1 || !td2 ) return TypeInt::CC;
1100 
1101   // This implements the Java bytecode dcmpl, so unordered returns -1.
1102   if( td1->is_nan() || td2->is_nan() )
1103     return TypeInt::CC_LT;
1104 
1105   if( td1->_d < td2->_d ) return TypeInt::CC_LT;
1106   if( td1->_d > td2->_d ) return TypeInt::CC_GT;


1406   //    if( _test._test == BoolTest::le ) {
1407   //      if( cmp1_op == Op_AddI &&
1408   //          phase->type( cmp1->in(2) ) == TypeInt::ONE )
1409   //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
1410   //      else if( cmp2_op == Op_AddI &&
1411   //         phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
1412   //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
1413   //    } else if( _test._test == BoolTest::lt ) {
1414   //      if( cmp1_op == Op_AddI &&
1415   //          phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
1416   //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
1417   //      else if( cmp2_op == Op_AddI &&
1418   //         phase->type( cmp2->in(2) ) == TypeInt::ONE )
1419   //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
1420   //    }
1421 }
1422 
1423 //------------------------------Value------------------------------------------
1424 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
1425 // based on local information.   If the input is constant, do it.
1426 const Type *BoolNode::Value( PhaseTransform *phase ) const {
1427   return _test.cc2logical( phase->type( in(1) ) );
1428 }
1429 
1430 #ifndef PRODUCT
1431 //------------------------------dump_spec--------------------------------------
1432 // Dump special per-node info
1433 void BoolNode::dump_spec(outputStream *st) const {
1434   st->print("[");
1435   _test.dump_on(st);
1436   st->print("]");
1437 }
1438 
1439 //-------------------------------related---------------------------------------
1440 // A BoolNode's related nodes are all of its data inputs, and all of its
1441 // outputs until control nodes are hit, which are included. In compact
1442 // representation, inputs till level 3 and immediate outputs are included.
1443 void BoolNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
1444   if (compact) {
1445     this->collect_nodes(in_rel, 3, false, true);
1446     this->collect_nodes(out_rel, -1, false, false);


1449     this->collect_nodes_out_all_ctrl_boundary(out_rel);
1450   }
1451 }
1452 #endif
1453 
1454 //----------------------is_counted_loop_exit_test------------------------------
1455 // Returns true if node is used by a counted loop node.
1456 bool BoolNode::is_counted_loop_exit_test() {
1457   for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
1458     Node* use = fast_out(i);
1459     if (use->is_CountedLoopEnd()) {
1460       return true;
1461     }
1462   }
1463   return false;
1464 }
1465 
1466 //=============================================================================
1467 //------------------------------Value------------------------------------------
1468 // Compute sqrt
1469 const Type *SqrtDNode::Value( PhaseTransform *phase ) const {
1470   const Type *t1 = phase->type( in(1) );
1471   if( t1 == Type::TOP ) return Type::TOP;
1472   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1473   double d = t1->getd();
1474   if( d < 0.0 ) return Type::DOUBLE;
1475   return TypeD::make( sqrt( d ) );
1476 }
1477 
1478 //=============================================================================
1479 //------------------------------Value------------------------------------------
1480 // Compute cos
1481 const Type *CosDNode::Value( PhaseTransform *phase ) const {
1482   const Type *t1 = phase->type( in(1) );
1483   if( t1 == Type::TOP ) return Type::TOP;
1484   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1485   double d = t1->getd();
1486   return TypeD::make( StubRoutines::intrinsic_cos( d ) );
1487 }
1488 
1489 //=============================================================================
1490 //------------------------------Value------------------------------------------
1491 // Compute sin
1492 const Type *SinDNode::Value( PhaseTransform *phase ) const {
1493   const Type *t1 = phase->type( in(1) );
1494   if( t1 == Type::TOP ) return Type::TOP;
1495   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1496   double d = t1->getd();
1497   return TypeD::make( StubRoutines::intrinsic_sin( d ) );
1498 }
1499 
1500 //=============================================================================
1501 //------------------------------Value------------------------------------------
1502 // Compute tan
1503 const Type *TanDNode::Value( PhaseTransform *phase ) const {
1504   const Type *t1 = phase->type( in(1) );
1505   if( t1 == Type::TOP ) return Type::TOP;
1506   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1507   double d = t1->getd();
1508   return TypeD::make( StubRoutines::intrinsic_tan( d ) );
1509 }
1510 
1511 //=============================================================================
1512 //------------------------------Value------------------------------------------
1513 // Compute log10
1514 const Type *Log10DNode::Value( PhaseTransform *phase ) const {
1515   const Type *t1 = phase->type( in(1) );
1516   if( t1 == Type::TOP ) return Type::TOP;
1517   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1518   double d = t1->getd();
1519   return TypeD::make( StubRoutines::intrinsic_log10( d ) );
1520 }
1521 


  29 #include "opto/callnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/loopnode.hpp"
  32 #include "opto/matcher.hpp"
  33 #include "opto/movenode.hpp"
  34 #include "opto/mulnode.hpp"
  35 #include "opto/opcodes.hpp"
  36 #include "opto/phaseX.hpp"
  37 #include "opto/subnode.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 
  40 // Portions of code courtesy of Clifford Click
  41 
  42 // Optimization - Graph Style
  43 
  44 #include "math.h"
  45 
  46 //=============================================================================
  47 //------------------------------Identity---------------------------------------
  48 // If right input is a constant 0, return the left input.
  49 Node* SubNode::Identity(PhaseGVN* phase) {
  50   assert(in(1) != this, "Must already have called Value");
  51   assert(in(2) != this, "Must already have called Value");
  52 
  53   // Remove double negation
  54   const Type *zero = add_id();
  55   if( phase->type( in(1) )->higher_equal( zero ) &&
  56       in(2)->Opcode() == Opcode() &&
  57       phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
  58     return in(2)->in(2);
  59   }
  60 
  61   // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y
  62   if( in(1)->Opcode() == Op_AddI ) {
  63     if( phase->eqv(in(1)->in(2),in(2)) )
  64       return in(1)->in(1);
  65     if (phase->eqv(in(1)->in(1),in(2)))
  66       return in(1)->in(2);
  67 
  68     // Also catch: "(X + Opaque2(Y)) - Y".  In this case, 'Y' is a loop-varying
  69     // trip counter and X is likely to be loop-invariant (that's how O2 Nodes


  83 const Type* SubNode::Value_common(PhaseTransform *phase) const {
  84   const Node* in1 = in(1);
  85   const Node* in2 = in(2);
  86   // Either input is TOP ==> the result is TOP
  87   const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
  88   if( t1 == Type::TOP ) return Type::TOP;
  89   const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
  90   if( t2 == Type::TOP ) return Type::TOP;
  91 
  92   // Not correct for SubFnode and AddFNode (must check for infinity)
  93   // Equal?  Subtract is zero
  94   if (in1->eqv_uncast(in2))  return add_id();
  95 
  96   // Either input is BOTTOM ==> the result is the local BOTTOM
  97   if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
  98     return bottom_type();
  99 
 100   return NULL;
 101 }
 102 
 103 const Type* SubNode::Value(PhaseGVN* phase) const {
 104   const Type* t = Value_common(phase);
 105   if (t != NULL) {
 106     return t;
 107   }
 108   const Type* t1 = phase->type(in(1));
 109   const Type* t2 = phase->type(in(2));
 110   return sub(t1,t2);            // Local flavor of type subtraction
 111 
 112 }
 113 
 114 //=============================================================================
 115 
 116 //------------------------------Helper function--------------------------------
 117 static bool ok_to_convert(Node* inc, Node* iv) {
 118     // Do not collapse (x+c0)-y if "+" is a loop increment, because the
 119     // "-" is loop invariant and collapsing extends the live-range of "x"
 120     // to overlap with the "+", forcing another register to be used in
 121     // the loop.
 122     // This test will be clearer with '&&' (apply DeMorgan's rule)
 123     // but I like the early cutouts that happen here.


 361 const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
 362   const TypeLong *r0 = t1->is_long(); // Handy access
 363   const TypeLong *r1 = t2->is_long();
 364   jlong lo = java_subtract(r0->_lo, r1->_hi);
 365   jlong hi = java_subtract(r0->_hi, r1->_lo);
 366 
 367   // We next check for 32-bit overflow.
 368   // If that happens, we just assume all integers are possible.
 369   if( (((r0->_lo ^ r1->_hi) >= 0) ||    // lo ends have same signs OR
 370        ((r0->_lo ^      lo) >= 0)) &&   // lo results have same signs AND
 371       (((r0->_hi ^ r1->_lo) >= 0) ||    // hi ends have same signs OR
 372        ((r0->_hi ^      hi) >= 0)) )    // hi results have same signs
 373     return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
 374   else                          // Overflow; assume all integers
 375     return TypeLong::LONG;
 376 }
 377 
 378 //=============================================================================
 379 //------------------------------Value------------------------------------------
 380 // A subtract node differences its two inputs.
 381 const Type* SubFPNode::Value(PhaseGVN* phase) const {
 382   const Node* in1 = in(1);
 383   const Node* in2 = in(2);
 384   // Either input is TOP ==> the result is TOP
 385   const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
 386   if( t1 == Type::TOP ) return Type::TOP;
 387   const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
 388   if( t2 == Type::TOP ) return Type::TOP;
 389 
 390   // if both operands are infinity of same sign, the result is NaN; do
 391   // not replace with zero
 392   if( (t1->is_finite() && t2->is_finite()) ) {
 393     if( phase->eqv(in1, in2) ) return add_id();
 394   }
 395 
 396   // Either input is BOTTOM ==> the result is the local BOTTOM
 397   const Type *bot = bottom_type();
 398   if( (t1 == bot) || (t2 == bot) ||
 399       (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
 400     return bot;
 401 


 477   // no folding if one of operands is infinity or NaN, do not do constant folding
 478   if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) {
 479     return TypeD::make( t1->getd() - t2->getd() );
 480   }
 481   else if( g_isnan(t1->getd()) ) {
 482     return t1;
 483   }
 484   else if( g_isnan(t2->getd()) ) {
 485     return t2;
 486   }
 487   else {
 488     return Type::DOUBLE;
 489   }
 490 }
 491 
 492 //=============================================================================
 493 //------------------------------Idealize---------------------------------------
 494 // Unlike SubNodes, compare must still flatten return value to the
 495 // range -1, 0, 1.
 496 // And optimizations like those for (X + Y) - X fail if overflow happens.
 497 Node* CmpNode::Identity(PhaseGVN* phase) {
 498   return this;
 499 }
 500 
 501 #ifndef PRODUCT
 502 //----------------------------related------------------------------------------
 503 // Related nodes of comparison nodes include all data inputs (until hitting a
 504 // control boundary) as well as all outputs until and including control nodes
 505 // as well as their projections. In compact mode, data inputs till depth 1 and
 506 // all outputs till depth 1 are considered.
 507 void CmpNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
 508   if (compact) {
 509     this->collect_nodes(in_rel, 1, false, true);
 510     this->collect_nodes(out_rel, -1, false, false);
 511   } else {
 512     this->collect_nodes_in_all_data(in_rel, false);
 513     this->collect_nodes_out_all_ctrl_boundary(out_rel);
 514     // Now, find all control nodes in out_rel, and include their projections
 515     // and projection targets (if any) in the result.
 516     GrowableArray<Node*> proj(Compile::current()->unique());
 517     for (GrowableArrayIterator<Node*> it = out_rel->begin(); it != out_rel->end(); ++it) {


 594     } else if (lo0 >= hi1) {
 595       return TypeInt::CC_GE;
 596     } else if (hi0 <= lo1) {
 597       // Check for special case in Hashtable::get.  (See below.)
 598       if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
 599         return TypeInt::CC_LT;
 600       return TypeInt::CC_LE;
 601     }
 602   }
 603   // Check for special case in Hashtable::get - the hash index is
 604   // mod'ed to the table size so the following range check is useless.
 605   // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
 606   // to be positive.
 607   // (This is a gross hack, since the sub method never
 608   // looks at the structure of the node in any other case.)
 609   if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
 610     return TypeInt::CC_LT;
 611   return TypeInt::CC;                   // else use worst case results
 612 }
 613 
 614 const Type* CmpUNode::Value(PhaseGVN* phase) const {
 615   const Type* t = SubNode::Value_common(phase);
 616   if (t != NULL) {
 617     return t;
 618   }
 619   const Node* in1 = in(1);
 620   const Node* in2 = in(2);
 621   const Type* t1 = phase->type(in1);
 622   const Type* t2 = phase->type(in2);
 623   assert(t1->isa_int(), "CmpU has only Int type inputs");
 624   if (t2 == TypeInt::INT) { // Compare to bottom?
 625     return bottom_type();
 626   }
 627   uint in1_op = in1->Opcode();
 628   if (in1_op == Op_AddI || in1_op == Op_SubI) {
 629     // The problem rise when result of AddI(SubI) may overflow
 630     // signed integer value. Let say the input type is
 631     // [256, maxint] then +128 will create 2 ranges due to
 632     // overflow: [minint, minint+127] and [384, maxint].
 633     // But C2 type system keep only 1 type range and as result
 634     // it use general [minint, maxint] for this case which we


1036     intptr_t bits0 = r0->get_con();
1037     if( r1->singleton() )
1038       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1039     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1040   } else if( r1->singleton() ) {
1041     intptr_t bits1 = r1->get_con();
1042     return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1043   } else
1044     return TypeInt::CC;
1045 }
1046 
1047 //------------------------------Ideal------------------------------------------
1048 Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
1049   return NULL;
1050 }
1051 
1052 //=============================================================================
1053 //------------------------------Value------------------------------------------
1054 // Simplify an CmpF (compare 2 floats ) node, based on local information.
1055 // If both inputs are constants, compare them.
1056 const Type* CmpFNode::Value(PhaseGVN* phase) const {
1057   const Node* in1 = in(1);
1058   const Node* in2 = in(2);
1059   // Either input is TOP ==> the result is TOP
1060   const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
1061   if( t1 == Type::TOP ) return Type::TOP;
1062   const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
1063   if( t2 == Type::TOP ) return Type::TOP;
1064 
1065   // Not constants?  Don't know squat - even if they are the same
1066   // value!  If they are NaN's they compare to LT instead of EQ.
1067   const TypeF *tf1 = t1->isa_float_constant();
1068   const TypeF *tf2 = t2->isa_float_constant();
1069   if( !tf1 || !tf2 ) return TypeInt::CC;
1070 
1071   // This implements the Java bytecode fcmpl, so unordered returns -1.
1072   if( tf1->is_nan() || tf2->is_nan() )
1073     return TypeInt::CC_LT;
1074 
1075   if( tf1->_f < tf2->_f ) return TypeInt::CC_LT;
1076   if( tf1->_f > tf2->_f ) return TypeInt::CC_GT;
1077   assert( tf1->_f == tf2->_f, "do not understand FP behavior" );
1078   return TypeInt::CC_EQ;
1079 }
1080 
1081 
1082 //=============================================================================
1083 //------------------------------Value------------------------------------------
1084 // Simplify an CmpD (compare 2 doubles ) node, based on local information.
1085 // If both inputs are constants, compare them.
1086 const Type* CmpDNode::Value(PhaseGVN* phase) const {
1087   const Node* in1 = in(1);
1088   const Node* in2 = in(2);
1089   // Either input is TOP ==> the result is TOP
1090   const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
1091   if( t1 == Type::TOP ) return Type::TOP;
1092   const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
1093   if( t2 == Type::TOP ) return Type::TOP;
1094 
1095   // Not constants?  Don't know squat - even if they are the same
1096   // value!  If they are NaN's they compare to LT instead of EQ.
1097   const TypeD *td1 = t1->isa_double_constant();
1098   const TypeD *td2 = t2->isa_double_constant();
1099   if( !td1 || !td2 ) return TypeInt::CC;
1100 
1101   // This implements the Java bytecode dcmpl, so unordered returns -1.
1102   if( td1->is_nan() || td2->is_nan() )
1103     return TypeInt::CC_LT;
1104 
1105   if( td1->_d < td2->_d ) return TypeInt::CC_LT;
1106   if( td1->_d > td2->_d ) return TypeInt::CC_GT;


1406   //    if( _test._test == BoolTest::le ) {
1407   //      if( cmp1_op == Op_AddI &&
1408   //          phase->type( cmp1->in(2) ) == TypeInt::ONE )
1409   //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
1410   //      else if( cmp2_op == Op_AddI &&
1411   //         phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
1412   //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
1413   //    } else if( _test._test == BoolTest::lt ) {
1414   //      if( cmp1_op == Op_AddI &&
1415   //          phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
1416   //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
1417   //      else if( cmp2_op == Op_AddI &&
1418   //         phase->type( cmp2->in(2) ) == TypeInt::ONE )
1419   //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
1420   //    }
1421 }
1422 
1423 //------------------------------Value------------------------------------------
1424 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
1425 // based on local information.   If the input is constant, do it.
1426 const Type* BoolNode::Value(PhaseGVN* phase) const {
1427   return _test.cc2logical( phase->type( in(1) ) );
1428 }
1429 
1430 #ifndef PRODUCT
1431 //------------------------------dump_spec--------------------------------------
1432 // Dump special per-node info
1433 void BoolNode::dump_spec(outputStream *st) const {
1434   st->print("[");
1435   _test.dump_on(st);
1436   st->print("]");
1437 }
1438 
1439 //-------------------------------related---------------------------------------
1440 // A BoolNode's related nodes are all of its data inputs, and all of its
1441 // outputs until control nodes are hit, which are included. In compact
1442 // representation, inputs till level 3 and immediate outputs are included.
1443 void BoolNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
1444   if (compact) {
1445     this->collect_nodes(in_rel, 3, false, true);
1446     this->collect_nodes(out_rel, -1, false, false);


1449     this->collect_nodes_out_all_ctrl_boundary(out_rel);
1450   }
1451 }
1452 #endif
1453 
1454 //----------------------is_counted_loop_exit_test------------------------------
1455 // Returns true if node is used by a counted loop node.
1456 bool BoolNode::is_counted_loop_exit_test() {
1457   for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
1458     Node* use = fast_out(i);
1459     if (use->is_CountedLoopEnd()) {
1460       return true;
1461     }
1462   }
1463   return false;
1464 }
1465 
1466 //=============================================================================
1467 //------------------------------Value------------------------------------------
1468 // Compute sqrt
1469 const Type* SqrtDNode::Value(PhaseGVN* phase) const {
1470   const Type *t1 = phase->type( in(1) );
1471   if( t1 == Type::TOP ) return Type::TOP;
1472   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1473   double d = t1->getd();
1474   if( d < 0.0 ) return Type::DOUBLE;
1475   return TypeD::make( sqrt( d ) );
1476 }
1477 
1478 //=============================================================================
1479 //------------------------------Value------------------------------------------
1480 // Compute cos
1481 const Type* CosDNode::Value(PhaseGVN* phase) const {
1482   const Type *t1 = phase->type( in(1) );
1483   if( t1 == Type::TOP ) return Type::TOP;
1484   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1485   double d = t1->getd();
1486   return TypeD::make( StubRoutines::intrinsic_cos( d ) );
1487 }
1488 
1489 //=============================================================================
1490 //------------------------------Value------------------------------------------
1491 // Compute sin
1492 const Type* SinDNode::Value(PhaseGVN* phase) const {
1493   const Type *t1 = phase->type( in(1) );
1494   if( t1 == Type::TOP ) return Type::TOP;
1495   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1496   double d = t1->getd();
1497   return TypeD::make( StubRoutines::intrinsic_sin( d ) );
1498 }
1499 
1500 //=============================================================================
1501 //------------------------------Value------------------------------------------
1502 // Compute tan
1503 const Type* TanDNode::Value(PhaseGVN* phase) const {
1504   const Type *t1 = phase->type( in(1) );
1505   if( t1 == Type::TOP ) return Type::TOP;
1506   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1507   double d = t1->getd();
1508   return TypeD::make( StubRoutines::intrinsic_tan( d ) );
1509 }
1510 
1511 //=============================================================================
1512 //------------------------------Value------------------------------------------
1513 // Compute log10
1514 const Type* Log10DNode::Value(PhaseGVN* phase) const {
1515   const Type *t1 = phase->type( in(1) );
1516   if( t1 == Type::TOP ) return Type::TOP;
1517   if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1518   double d = t1->getd();
1519   return TypeD::make( StubRoutines::intrinsic_log10( d ) );
1520 }
1521 
< prev index next >