src/share/vm/opto/subnode.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 8042786 Sdiff src/share/vm/opto

src/share/vm/opto/subnode.cpp

Print this page




  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
  70     // are originally used, although the optimizer sometimes jiggers things).
  71     // This folding through an O2 removes a loop-exit use of a loop-varying
  72     // value and generally lowers register pressure in and around the loop.
  73     if( in(1)->in(2)->Opcode() == Op_Opaque2 &&
  74         phase->eqv(in(1)->in(2)->in(1),in(2)) )
  75       return in(1)->in(1);
  76   }
  77 
  78   return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this;
  79 }
  80 
  81 //------------------------------Value------------------------------------------
  82 // A subtract node differences it's two inputs.
  83 const Type *SubNode::Value( 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 sub(t1,t2);            // Local flavor of type subtraction
 101 
 102 }
 103 
 104 //=============================================================================
 105 
 106 //------------------------------Helper function--------------------------------
 107 static bool ok_to_convert(Node* inc, Node* iv) {
 108     // Do not collapse (x+c0)-y if "+" is a loop increment, because the
 109     // "-" is loop invariant and collapsing extends the live-range of "x"
 110     // to overlap with the "+", forcing another register to be used in
 111     // the loop.
 112     // This test will be clearer with '&&' (apply DeMorgan's rule)
 113     // but I like the early cutouts that happen here.
 114     const PhiNode *phi;
 115     if( ( !inc->in(1)->is_Phi() ||
 116           !(phi=inc->in(1)->as_Phi()) ||
 117           phi->is_copy() ||
 118           !phi->region()->is_CountedLoop() ||
 119           inc != phi->region()->as_CountedLoop()->incr() )


 553     } else if (lo0 >= hi1) {
 554       return TypeInt::CC_GE;
 555     } else if (hi0 <= lo1) {
 556       // Check for special case in Hashtable::get.  (See below.)
 557       if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
 558         return TypeInt::CC_LT;
 559       return TypeInt::CC_LE;
 560     }
 561   }
 562   // Check for special case in Hashtable::get - the hash index is
 563   // mod'ed to the table size so the following range check is useless.
 564   // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
 565   // to be positive.
 566   // (This is a gross hack, since the sub method never
 567   // looks at the structure of the node in any other case.)
 568   if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
 569     return TypeInt::CC_LT;
 570   return TypeInt::CC;                   // else use worst case results
 571 }
 572 








































































 573 bool CmpUNode::is_index_range_check() const {
 574   // Check for the "(X ModI Y) CmpU Y" shape
 575   return (in(1)->Opcode() == Op_ModI &&
 576           in(1)->in(2)->eqv_uncast(in(2)));
 577 }
 578 
 579 //------------------------------Idealize---------------------------------------
 580 Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
 581   if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
 582     switch (in(1)->Opcode()) {
 583     case Op_CmpL3:              // Collapse a CmpL3/CmpI into a CmpL
 584       return new (phase->C) CmpLNode(in(1)->in(1),in(1)->in(2));
 585     case Op_CmpF3:              // Collapse a CmpF3/CmpI into a CmpF
 586       return new (phase->C) CmpFNode(in(1)->in(1),in(1)->in(2));
 587     case Op_CmpD3:              // Collapse a CmpD3/CmpI into a CmpD
 588       return new (phase->C) CmpDNode(in(1)->in(1),in(1)->in(2));
 589     //case Op_SubI:
 590       // If (x - y) cannot overflow, then ((x - y) <?> 0)
 591       // can be turned into (x <?> y).
 592       // This is handled (with more general cases) by Ideal_sub_algebra.




  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
  70     // are originally used, although the optimizer sometimes jiggers things).
  71     // This folding through an O2 removes a loop-exit use of a loop-varying
  72     // value and generally lowers register pressure in and around the loop.
  73     if( in(1)->in(2)->Opcode() == Op_Opaque2 &&
  74         phase->eqv(in(1)->in(2)->in(1),in(2)) )
  75       return in(1)->in(1);
  76   }
  77 
  78   return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this;
  79 }
  80 
  81 //------------------------------Value------------------------------------------
  82 // A subtract node differences it's two inputs.
  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.
 124     const PhiNode *phi;
 125     if( ( !inc->in(1)->is_Phi() ||
 126           !(phi=inc->in(1)->as_Phi()) ||
 127           phi->is_copy() ||
 128           !phi->region()->is_CountedLoop() ||
 129           inc != phi->region()->as_CountedLoop()->incr() )


 563     } else if (lo0 >= hi1) {
 564       return TypeInt::CC_GE;
 565     } else if (hi0 <= lo1) {
 566       // Check for special case in Hashtable::get.  (See below.)
 567       if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
 568         return TypeInt::CC_LT;
 569       return TypeInt::CC_LE;
 570     }
 571   }
 572   // Check for special case in Hashtable::get - the hash index is
 573   // mod'ed to the table size so the following range check is useless.
 574   // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
 575   // to be positive.
 576   // (This is a gross hack, since the sub method never
 577   // looks at the structure of the node in any other case.)
 578   if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
 579     return TypeInt::CC_LT;
 580   return TypeInt::CC;                   // else use worst case results
 581 }
 582 
 583 const Type* CmpUNode::Value(PhaseTransform *phase) const {
 584   const Type* t = SubNode::Value_common(phase);
 585   if (t != NULL) {
 586     return t;
 587   }
 588   const Node* in1 = in(1);
 589   const Node* in2 = in(2);
 590   const Type* t1 = phase->type(in1);
 591   const Type* t2 = phase->type(in2);
 592   assert(t1->isa_int(), "CmpU has only Int type inputs");
 593   if (t2 == TypeInt::INT) { // Compare to bottom?
 594     return bottom_type();
 595   }
 596   uint in1_op = in1->Opcode();
 597   if (in1_op == Op_AddI || in1_op == Op_SubI) {
 598     // The problem rise when result of AddI(SubI) may overflow
 599     // signed integer value. Let say the input type is
 600     // [256, maxint] then +128 will create 2 ranges due to
 601     // overflow: [minint, minint+127] and [384, maxint].
 602     // But C2 type system keep only 1 type range and as result
 603     // it use general [minint, maxint] for this case which we
 604     // can't optimize.
 605     //
 606     // Make 2 separate type ranges based on types of AddI(SubI) inputs
 607     // and compare results of their compare. If results are the same
 608     // CmpU node can be optimized.
 609     const Node* in11 = in1->in(1);
 610     const Node* in12 = in1->in(2);
 611     const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11);
 612     const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12);
 613     // Skip cases when input types are top or bottom.
 614     if ((t11 != Type::TOP) && (t11 != TypeInt::INT) &&
 615         (t12 != Type::TOP) && (t12 != TypeInt::INT)) {
 616       const TypeInt *r0 = t11->is_int();
 617       const TypeInt *r1 = t12->is_int();
 618       jlong lo0 = r0->_lo;
 619       jlong hi0 = r0->_hi;
 620       jlong lo1 = r1->_lo;
 621       jlong hi1 = r1->_hi;
 622       if (in1_op == Op_SubI) {
 623         jlong tmp = hi1;
 624         hi1 = -lo1;
 625         lo1 = -tmp;
 626       }
 627       jlong lol = lo0 + lo1;
 628       jlong hil = hi0 + hi1;
 629       bool underflow = lol != (int)lol;
 630       bool overflow  = hil != (int)hil;
 631       // Use sub(t1, t2) when there is no overflow (one type range)
 632       // or when both overflow and underflow (too complex).
 633       if (underflow != overflow) {
 634         // Overflow only on one boundary, compare 2 type ranges.
 635         int lo_r1 = min_jint;
 636         int hi_r1 = (int)hil;
 637         int lo_r2 = (int)lol;
 638         int hi_r2 = max_jint;
 639 
 640         int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here
 641         const TypeInt* tr1 = TypeInt::make(lo_r1, hi_r1, w);
 642         const TypeInt* tr2 = TypeInt::make(lo_r2, hi_r2, w);
 643         const Type* cmp1 = sub(tr1, t2);
 644         const Type* cmp2 = sub(tr2, t2);
 645         if (cmp1 == cmp2) {
 646           return cmp1; // Hit!
 647         }
 648       }
 649     }
 650   }
 651 
 652   return sub(t1, t2);            // Local flavor of type subtraction
 653 }
 654 
 655 bool CmpUNode::is_index_range_check() const {
 656   // Check for the "(X ModI Y) CmpU Y" shape
 657   return (in(1)->Opcode() == Op_ModI &&
 658           in(1)->in(2)->eqv_uncast(in(2)));
 659 }
 660 
 661 //------------------------------Idealize---------------------------------------
 662 Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
 663   if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
 664     switch (in(1)->Opcode()) {
 665     case Op_CmpL3:              // Collapse a CmpL3/CmpI into a CmpL
 666       return new (phase->C) CmpLNode(in(1)->in(1),in(1)->in(2));
 667     case Op_CmpF3:              // Collapse a CmpF3/CmpI into a CmpF
 668       return new (phase->C) CmpFNode(in(1)->in(1),in(1)->in(2));
 669     case Op_CmpD3:              // Collapse a CmpD3/CmpI into a CmpD
 670       return new (phase->C) CmpDNode(in(1)->in(1),in(1)->in(2));
 671     //case Op_SubI:
 672       // If (x - y) cannot overflow, then ((x - y) <?> 0)
 673       // can be turned into (x <?> y).
 674       // This is handled (with more general cases) by Ideal_sub_algebra.


src/share/vm/opto/subnode.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File