< prev index next >

src/share/vm/opto/addnode.cpp

Print this page




  30 #include "opto/connode.hpp"
  31 #include "opto/machnode.hpp"
  32 #include "opto/mulnode.hpp"
  33 #include "opto/phaseX.hpp"
  34 #include "opto/subnode.hpp"
  35 
  36 // Portions of code courtesy of Clifford Click
  37 
  38 // Classic Add functionality.  This covers all the usual 'add' behaviors for
  39 // an algebraic ring.  Add-integer, add-float, add-double, and binary-or are
  40 // all inherited from this class.  The various identity values are supplied
  41 // by virtual functions.
  42 
  43 
  44 //=============================================================================
  45 //------------------------------hash-------------------------------------------
  46 // Hash function over AddNodes.  Needs to be commutative; i.e., I swap
  47 // (commute) inputs to AddNodes willy-nilly so the hash function must return
  48 // the same value in the presence of edge swapping.
  49 uint AddNode::hash() const {
  50   return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
  51 }
  52 
  53 //------------------------------Identity---------------------------------------
  54 // If either input is a constant 0, return the other input.
  55 Node* AddNode::Identity(PhaseGVN* phase) {
  56   const Type *zero = add_id();  // The additive identity
  57   if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);
  58   if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);
  59   return this;
  60 }
  61 
  62 //------------------------------commute----------------------------------------
  63 // Commute operands to move loads and constants to the right.
  64 static bool commute(Node *add, bool con_left, bool con_right) {
  65   Node *in1 = add->in(1);
  66   Node *in2 = add->in(2);
  67 
  68   // Convert "1+x" into "x+1".
  69   // Right is a constant; leave it
  70   if( con_right ) return false;


 106 }
 107 
 108 //------------------------------Idealize---------------------------------------
 109 // If we get here, we assume we are associative!
 110 Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 111   const Type *t1 = phase->type( in(1) );
 112   const Type *t2 = phase->type( in(2) );
 113   bool con_left  = t1->singleton();
 114   bool con_right = t2->singleton();
 115 
 116   // Check for commutative operation desired
 117   if( commute(this,con_left,con_right) ) return this;
 118 
 119   AddNode *progress = NULL;             // Progress flag
 120 
 121   // Convert "(x+1)+2" into "x+(1+2)".  If the right input is a
 122   // constant, and the left input is an add of a constant, flatten the
 123   // expression tree.
 124   Node *add1 = in(1);
 125   Node *add2 = in(2);
 126   int add1_op = add1->Opcode();
 127   int this_op = Opcode();
 128   if( con_right && t2 != Type::TOP && // Right input is a constant?
 129       add1_op == this_op ) { // Left input is an Add?
 130 
 131     // Type of left _in right input
 132     const Type *t12 = phase->type( add1->in(2) );
 133     if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant?
 134       // Check for rare case of closed data cycle which can happen inside
 135       // unreachable loops. In these cases the computation is undefined.
 136 #ifdef ASSERT
 137       Node *add11    = add1->in(1);
 138       int   add11_op = add11->Opcode();
 139       if( (add1 == add1->in(1))
 140          || (add11_op == this_op && add11->in(1) == add1) ) {
 141         assert(false, "dead loop in AddNode::Ideal");
 142       }
 143 #endif
 144       // The Add of the flattened expression
 145       Node *x1 = add1->in(1);
 146       Node *x2 = phase->makecon( add1->as_Add()->add_ring( t2, t12 ));
 147       PhaseIterGVN *igvn = phase->is_IterGVN();
 148       if( igvn ) {
 149         set_req_X(2,x2,igvn);
 150         set_req_X(1,x1,igvn);
 151       } else {
 152         set_req(2,x2);
 153         set_req(1,x1);
 154       }
 155       progress = this;            // Made progress
 156       add1 = in(1);
 157       add1_op = add1->Opcode();
 158     }
 159   }
 160 
 161   // Convert "(x+1)+y" into "(x+y)+1".  Push constants down the expression tree.
 162   if( add1_op == this_op && !con_right ) {
 163     Node *a12 = add1->in(2);
 164     const Type *t12 = phase->type( a12 );
 165     if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&
 166        !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) {
 167       assert(add1->in(1) != this, "dead loop in AddNode::Ideal");
 168       add2 = add1->clone();
 169       add2->set_req(2, in(2));
 170       add2 = phase->transform(add2);
 171       set_req(1, add2);
 172       set_req(2, a12);
 173       progress = this;
 174       add2 = a12;
 175     }
 176   }
 177 
 178   // Convert "x+(y+1)" into "(x+y)+1".  Push constants down the expression tree.
 179   int add2_op = add2->Opcode();
 180   if( add2_op == this_op && !con_left ) {
 181     Node *a22 = add2->in(2);
 182     const Type *t22 = phase->type( a22 );
 183     if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&
 184        !(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) {
 185       assert(add2->in(1) != this, "dead loop in AddNode::Ideal");
 186       Node *addx = add2->clone();
 187       addx->set_req(1, in(1));
 188       addx->set_req(2, add2->in(1));
 189       addx = phase->transform(addx);
 190       set_req(1, addx);
 191       set_req(2, a22);
 192       progress = this;
 193       PhaseIterGVN *igvn = phase->is_IterGVN();
 194       if (add2->outcnt() == 0 && igvn) {
 195         // add disconnected.
 196         igvn->_worklist.push(add2);
 197       }
 198     }
 199   }


 223 
 224   return add_ring(t1,t2);               // Local flavor of type addition
 225 }
 226 
 227 //------------------------------add_identity-----------------------------------
 228 // Check for addition of the identity
 229 const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const {
 230   const Type *zero = add_id();  // The additive identity
 231   if( t1->higher_equal( zero ) ) return t2;
 232   if( t2->higher_equal( zero ) ) return t1;
 233 
 234   return NULL;
 235 }
 236 
 237 
 238 //=============================================================================
 239 //------------------------------Idealize---------------------------------------
 240 Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 241   Node* in1 = in(1);
 242   Node* in2 = in(2);
 243   int op1 = in1->Opcode();
 244   int op2 = in2->Opcode();
 245   // Fold (con1-x)+con2 into (con1+con2)-x
 246   if ( op1 == Op_AddI && op2 == Op_SubI ) {
 247     // Swap edges to try optimizations below
 248     in1 = in2;
 249     in2 = in(1);
 250     op1 = op2;
 251     op2 = in2->Opcode();
 252   }
 253   if( op1 == Op_SubI ) {
 254     const Type *t_sub1 = phase->type( in1->in(1) );
 255     const Type *t_2    = phase->type( in2        );
 256     if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
 257       return new SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
 258     // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
 259     if( op2 == Op_SubI ) {
 260       // Check for dead cycle: d = (a-b)+(c-d)
 261       assert( in1->in(2) != this && in2->in(2) != this,
 262               "dead loop in AddINode::Ideal" );
 263       Node *sub  = new SubINode(NULL, NULL);
 264       sub->init_req(1, phase->transform(new AddINode(in1->in(1), in2->in(1) ) ));
 265       sub->init_req(2, phase->transform(new AddINode(in1->in(2), in2->in(2) ) ));
 266       return sub;
 267     }
 268     // Convert "(a-b)+(b+c)" into "(a+c)"
 269     if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) {
 270       assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
 271       return new AddINode(in1->in(1), in2->in(2));
 272     }
 273     // Convert "(a-b)+(c+b)" into "(a+c)"
 274     if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) {
 275       assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
 276       return new AddINode(in1->in(1), in2->in(1));
 277     }
 278     // Convert "(a-b)+(b-c)" into "(a-c)"
 279     if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) {
 280       assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
 281       return new SubINode(in1->in(1), in2->in(2));
 282     }
 283     // Convert "(a-b)+(c-a)" into "(c-b)"
 284     if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) {
 285       assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
 286       return new SubINode(in2->in(1), in1->in(2));
 287     }
 288   }
 289 
 290   // Convert "x+(0-y)" into "(x-y)"
 291   if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
 292     return new SubINode(in1, in2->in(2) );
 293 
 294   // Convert "(0-y)+x" into "(x-y)"
 295   if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
 296     return new SubINode( in2, in1->in(2) );
 297 
 298   // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.
 299   // Helps with array allocation math constant folding
 300   // See 4790063:
 301   // Unrestricted transformation is unsafe for some runtime values of 'x'
 302   // ( x ==  0, z == 1, y == -1 ) fails
 303   // ( x == -5, z == 1, y ==  1 ) fails
 304   // Transform works for small z and small negative y when the addition
 305   // (x + (y << z)) does not cross zero.
 306   // Implement support for negative y and (x >= -(y << z))
 307   // Have not observed cases where type information exists to support
 308   // positive y and (x <= -(y << z))
 309   if( op1 == Op_URShiftI && op2 == Op_ConI &&
 310       in1->in(2)->Opcode() == Op_ConI ) {
 311     jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
 312     jint y = phase->type( in2 )->is_int()->get_con();
 313 
 314     if( z < 5 && -5 < y && y < 0 ) {
 315       const Type *t_in11 = phase->type(in1->in(1));
 316       if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
 317         Node *a = phase->transform( new AddINode( in1->in(1), phase->intcon(y<<z) ) );
 318         return new URShiftINode( a, in1->in(2) );
 319       }
 320     }
 321   }
 322 
 323   return AddNode::Ideal(phase, can_reshape);
 324 }
 325 
 326 
 327 //------------------------------Identity---------------------------------------
 328 // Fold (x-y)+y  OR  y+(x-y)  into  x
 329 Node* AddINode::Identity(PhaseGVN* phase) {
 330   if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
 331     return in(1)->in(1);
 332   }
 333   else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
 334     return in(2)->in(1);
 335   }
 336   return AddNode::Identity(phase);
 337 }
 338 
 339 
 340 //------------------------------add_ring---------------------------------------
 341 // Supplied function returns the sum of the inputs.  Guaranteed never
 342 // to be passed a TOP or BOTTOM type, these are filtered out by
 343 // pre-check.
 344 const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {
 345   const TypeInt *r0 = t0->is_int(); // Handy access
 346   const TypeInt *r1 = t1->is_int();
 347   int lo = java_add(r0->_lo, r1->_lo);
 348   int hi = java_add(r0->_hi, r1->_hi);
 349   if( !(r0->is_con() && r1->is_con()) ) {
 350     // Not both constants, compute approximate result
 351     if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
 352       lo = min_jint; hi = max_jint; // Underflow on the low side
 353     }
 354     if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
 355       lo = min_jint; hi = max_jint; // Overflow on the high side
 356     }
 357     if( lo > hi ) {               // Handle overflow
 358       lo = min_jint; hi = max_jint;
 359     }
 360   } else {
 361     // both constants, compute precise result using 'lo' and 'hi'
 362     // Semantics define overflow and underflow for integer addition
 363     // as expected.  In particular: 0x80000000 + 0x80000000 --> 0x0
 364   }
 365   return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
 366 }
 367 
 368 
 369 //=============================================================================
 370 //------------------------------Idealize---------------------------------------
 371 Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 372   Node* in1 = in(1);
 373   Node* in2 = in(2);
 374   int op1 = in1->Opcode();
 375   int op2 = in2->Opcode();
 376   // Fold (con1-x)+con2 into (con1+con2)-x
 377   if ( op1 == Op_AddL && op2 == Op_SubL ) {
 378     // Swap edges to try optimizations below
 379     in1 = in2;
 380     in2 = in(1);
 381     op1 = op2;
 382     op2 = in2->Opcode();
 383   }
 384   // Fold (con1-x)+con2 into (con1+con2)-x
 385   if( op1 == Op_SubL ) {
 386     const Type *t_sub1 = phase->type( in1->in(1) );
 387     const Type *t_2    = phase->type( in2        );
 388     if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
 389       return new SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
 390     // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
 391     if( op2 == Op_SubL ) {
 392       // Check for dead cycle: d = (a-b)+(c-d)
 393       assert( in1->in(2) != this && in2->in(2) != this,
 394               "dead loop in AddLNode::Ideal" );
 395       Node *sub  = new SubLNode(NULL, NULL);
 396       sub->init_req(1, phase->transform(new AddLNode(in1->in(1), in2->in(1) ) ));
 397       sub->init_req(2, phase->transform(new AddLNode(in1->in(2), in2->in(2) ) ));
 398       return sub;
 399     }
 400     // Convert "(a-b)+(b+c)" into "(a+c)"
 401     if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {
 402       assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
 403       return new AddLNode(in1->in(1), in2->in(2));
 404     }
 405     // Convert "(a-b)+(c+b)" into "(a+c)"
 406     if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {
 407       assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
 408       return new AddLNode(in1->in(1), in2->in(1));
 409     }
 410     // Convert "(a-b)+(b-c)" into "(a-c)"
 411     if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {
 412       assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
 413       return new SubLNode(in1->in(1), in2->in(2));
 414     }
 415     // Convert "(a-b)+(c-a)" into "(c-b)"
 416     if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) {
 417       assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
 418       return new SubLNode(in2->in(1), in1->in(2));
 419     }
 420   }
 421 
 422   // Convert "x+(0-y)" into "(x-y)"
 423   if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
 424     return new SubLNode( in1, in2->in(2) );
 425 
 426   // Convert "(0-y)+x" into "(x-y)"
 427   if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
 428     return new SubLNode( in2, in1->in(2) );
 429 
 430   // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
 431   // into "(X<<1)+Y" and let shift-folding happen.
 432   if( op2 == Op_AddL &&
 433       in2->in(1) == in1 &&
 434       op1 != Op_ConL &&
 435       0 ) {
 436     Node *shift = phase->transform(new LShiftLNode(in1,phase->intcon(1)));
 437     return new AddLNode(shift,in2->in(2));
 438   }
 439 
 440   return AddNode::Ideal(phase, can_reshape);
 441 }
 442 
 443 
 444 //------------------------------Identity---------------------------------------
 445 // Fold (x-y)+y  OR  y+(x-y)  into  x
 446 Node* AddLNode::Identity(PhaseGVN* phase) {
 447   if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
 448     return in(1)->in(1);
 449   }
 450   else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
 451     return in(2)->in(1);
 452   }
 453   return AddNode::Identity(phase);
 454 }
 455 
 456 
 457 //------------------------------add_ring---------------------------------------
 458 // Supplied function returns the sum of the inputs.  Guaranteed never
 459 // to be passed a TOP or BOTTOM type, these are filtered out by
 460 // pre-check.
 461 const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {
 462   const TypeLong *r0 = t0->is_long(); // Handy access
 463   const TypeLong *r1 = t1->is_long();
 464   jlong lo = java_add(r0->_lo, r1->_lo);
 465   jlong hi = java_add(r0->_hi, r1->_hi);
 466   if( !(r0->is_con() && r1->is_con()) ) {
 467     // Not both constants, compute approximate result
 468     if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
 469       lo =min_jlong; hi = max_jlong; // Underflow on the low side
 470     }


 606         set_req(Offset,offset);
 607       }
 608       return this;
 609     }
 610   }
 611 
 612   // Raw pointers?
 613   if( in(Base)->bottom_type() == Type::TOP ) {
 614     // If this is a NULL+long form (from unsafe accesses), switch to a rawptr.
 615     if (phase->type(in(Address)) == TypePtr::NULL_PTR) {
 616       Node* offset = in(Offset);
 617       return new CastX2PNode(offset);
 618     }
 619   }
 620 
 621   // If the right is an add of a constant, push the offset down.
 622   // Convert: (ptr + (offset+con)) into (ptr+offset)+con.
 623   // The idea is to merge array_base+scaled_index groups together,
 624   // and only have different constant offsets from the same base.
 625   const Node *add = in(Offset);
 626   if( add->Opcode() == Op_AddX && add->in(1) != add ) {
 627     const Type *t22 = phase->type( add->in(2) );
 628     if( t22->singleton() && (t22 != Type::TOP) ) {  // Right input is an add of a constant?
 629       set_req(Address, phase->transform(new AddPNode(in(Base),in(Address),add->in(1))));
 630       set_req(Offset, add->in(2));
 631       PhaseIterGVN *igvn = phase->is_IterGVN();
 632       if (add->outcnt() == 0 && igvn) {
 633         // add disconnected.
 634         igvn->_worklist.push((Node*)add);
 635       }
 636       return this;              // Made progress
 637     }
 638   }
 639 
 640   return NULL;                  // No progress
 641 }
 642 
 643 //------------------------------bottom_type------------------------------------
 644 // Bottom-type is the pointer-type with unknown offset.
 645 const Type *AddPNode::bottom_type() const {
 646   if (in(Address) == NULL)  return TypePtr::BOTTOM;
 647   const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
 648   if( !tp ) return Type::TOP;   // TOP input means TOP output
 649   assert( in(Offset)->Opcode() != Op_ConP, "" );
 650   const Type *t = in(Offset)->bottom_type();
 651   if( t == Type::TOP )
 652     return tp->add_offset(Type::OffsetTop);
 653   const TypeX *tx = t->is_intptr_t();
 654   intptr_t txoffset = Type::OffsetBot;
 655   if (tx->is_con()) {   // Left input is an add of a constant?
 656     txoffset = tx->get_con();
 657   }
 658   return tp->add_offset(txoffset);
 659 }
 660 
 661 //------------------------------Value------------------------------------------
 662 const Type* AddPNode::Value(PhaseGVN* phase) const {
 663   // Either input is TOP ==> the result is TOP
 664   const Type *t1 = phase->type( in(Address) );
 665   const Type *t2 = phase->type( in(Offset) );
 666   if( t1 == Type::TOP ) return Type::TOP;
 667   if( t2 == Type::TOP ) return Type::TOP;
 668 
 669   // Left input is a pointer


 837 // Supplied function returns the sum of the inputs.
 838 const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const {
 839   const TypeInt *r0 = t0->is_int(); // Handy access
 840   const TypeInt *r1 = t1->is_int();
 841 
 842   // Otherwise just MAX them bits.
 843   return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
 844 }
 845 
 846 //=============================================================================
 847 //------------------------------Idealize---------------------------------------
 848 // MINs show up in range-check loop limit calculations.  Look for
 849 // "MIN2(x+c0,MIN2(y,x+c1))".  Pick the smaller constant: "MIN2(x+c0,y)"
 850 Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 851   Node *progress = NULL;
 852   // Force a right-spline graph
 853   Node *l = in(1);
 854   Node *r = in(2);
 855   // Transform  MinI1( MinI2(a,b), c)  into  MinI1( a, MinI2(b,c) )
 856   // to force a right-spline graph for the rest of MinINode::Ideal().
 857   if( l->Opcode() == Op_MinI ) {
 858     assert( l != l->in(1), "dead loop in MinINode::Ideal" );
 859     r = phase->transform(new MinINode(l->in(2),r));
 860     l = l->in(1);
 861     set_req(1, l);
 862     set_req(2, r);
 863     return this;
 864   }
 865 
 866   // Get left input & constant
 867   Node *x = l;
 868   int x_off = 0;
 869   if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant
 870       x->in(2)->is_Con() ) {
 871     const Type *t = x->in(2)->bottom_type();
 872     if( t == Type::TOP ) return NULL;  // No progress
 873     x_off = t->is_int()->get_con();
 874     x = x->in(1);
 875   }
 876 
 877   // Scan a right-spline-tree for MINs
 878   Node *y = r;
 879   int y_off = 0;
 880   // Check final part of MIN tree
 881   if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant
 882       y->in(2)->is_Con() ) {
 883     const Type *t = y->in(2)->bottom_type();
 884     if( t == Type::TOP ) return NULL;  // No progress
 885     y_off = t->is_int()->get_con();
 886     y = y->in(1);
 887   }
 888   if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) {
 889     swap_edges(1, 2);
 890     return this;
 891   }
 892 
 893 
 894   if( r->Opcode() == Op_MinI ) {
 895     assert( r != r->in(2), "dead loop in MinINode::Ideal" );
 896     y = r->in(1);
 897     // Check final part of MIN tree
 898     if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant
 899         y->in(2)->is_Con() ) {
 900       const Type *t = y->in(2)->bottom_type();
 901       if( t == Type::TOP ) return NULL;  // No progress
 902       y_off = t->is_int()->get_con();
 903       y = y->in(1);
 904     }
 905 
 906     if( x->_idx > y->_idx )
 907       return new MinINode(r->in(1),phase->transform(new MinINode(l,r->in(2))));
 908 
 909     // See if covers: MIN2(x+c0,MIN2(y+c1,z))
 910     if( !phase->eqv(x,y) ) return NULL;
 911     // If (y == x) transform MIN2(x+c0, MIN2(x+c1,z)) into
 912     // MIN2(x+c0 or x+c1 which less, z).
 913     return new MinINode(phase->transform(new AddINode(x,phase->intcon(MIN2(x_off,y_off)))),r->in(2));
 914   } else {
 915     // See if covers: MIN2(x+c0,y+c1)
 916     if( !phase->eqv(x,y) ) return NULL;
 917     // If (y == x) transform MIN2(x+c0,x+c1) into x+c0 or x+c1 which less.
 918     return new AddINode(x,phase->intcon(MIN2(x_off,y_off)));


  30 #include "opto/connode.hpp"
  31 #include "opto/machnode.hpp"
  32 #include "opto/mulnode.hpp"
  33 #include "opto/phaseX.hpp"
  34 #include "opto/subnode.hpp"
  35 
  36 // Portions of code courtesy of Clifford Click
  37 
  38 // Classic Add functionality.  This covers all the usual 'add' behaviors for
  39 // an algebraic ring.  Add-integer, add-float, add-double, and binary-or are
  40 // all inherited from this class.  The various identity values are supplied
  41 // by virtual functions.
  42 
  43 
  44 //=============================================================================
  45 //------------------------------hash-------------------------------------------
  46 // Hash function over AddNodes.  Needs to be commutative; i.e., I swap
  47 // (commute) inputs to AddNodes willy-nilly so the hash function must return
  48 // the same value in the presence of edge swapping.
  49 uint AddNode::hash() const {
  50   return (uintptr_t)in(1) + (uintptr_t)in(2) + static_cast<uint>(Opcode());
  51 }
  52 
  53 //------------------------------Identity---------------------------------------
  54 // If either input is a constant 0, return the other input.
  55 Node* AddNode::Identity(PhaseGVN* phase) {
  56   const Type *zero = add_id();  // The additive identity
  57   if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);
  58   if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);
  59   return this;
  60 }
  61 
  62 //------------------------------commute----------------------------------------
  63 // Commute operands to move loads and constants to the right.
  64 static bool commute(Node *add, bool con_left, bool con_right) {
  65   Node *in1 = add->in(1);
  66   Node *in2 = add->in(2);
  67 
  68   // Convert "1+x" into "x+1".
  69   // Right is a constant; leave it
  70   if( con_right ) return false;


 106 }
 107 
 108 //------------------------------Idealize---------------------------------------
 109 // If we get here, we assume we are associative!
 110 Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 111   const Type *t1 = phase->type( in(1) );
 112   const Type *t2 = phase->type( in(2) );
 113   bool con_left  = t1->singleton();
 114   bool con_right = t2->singleton();
 115 
 116   // Check for commutative operation desired
 117   if( commute(this,con_left,con_right) ) return this;
 118 
 119   AddNode *progress = NULL;             // Progress flag
 120 
 121   // Convert "(x+1)+2" into "x+(1+2)".  If the right input is a
 122   // constant, and the left input is an add of a constant, flatten the
 123   // expression tree.
 124   Node *add1 = in(1);
 125   Node *add2 = in(2);
 126   Opcodes add1_op = add1->Opcode();
 127   Opcodes this_op = Opcode();
 128   if( con_right && t2 != Type::TOP && // Right input is a constant?
 129       add1_op == this_op ) { // Left input is an Add?
 130 
 131     // Type of left _in right input
 132     const Type *t12 = phase->type( add1->in(2) );
 133     if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant?
 134       // Check for rare case of closed data cycle which can happen inside
 135       // unreachable loops. In these cases the computation is undefined.
 136 #ifdef ASSERT
 137       Node *add11    = add1->in(1);
 138       Opcodes  add11_op = add11->Opcode();
 139       if( (add1 == add1->in(1))
 140          || (add11_op == this_op && add11->in(1) == add1) ) {
 141         assert(false, "dead loop in AddNode::Ideal");
 142       }
 143 #endif
 144       // The Add of the flattened expression
 145       Node *x1 = add1->in(1);
 146       Node *x2 = phase->makecon( add1->as_Add()->add_ring( t2, t12 ));
 147       PhaseIterGVN *igvn = phase->is_IterGVN();
 148       if( igvn ) {
 149         set_req_X(2,x2,igvn);
 150         set_req_X(1,x1,igvn);
 151       } else {
 152         set_req(2,x2);
 153         set_req(1,x1);
 154       }
 155       progress = this;            // Made progress
 156       add1 = in(1);
 157       add1_op = add1->Opcode();
 158     }
 159   }
 160 
 161   // Convert "(x+1)+y" into "(x+y)+1".  Push constants down the expression tree.
 162   if( add1_op == this_op && !con_right ) {
 163     Node *a12 = add1->in(2);
 164     const Type *t12 = phase->type( a12 );
 165     if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&
 166        !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) {
 167       assert(add1->in(1) != this, "dead loop in AddNode::Ideal");
 168       add2 = add1->clone();
 169       add2->set_req(2, in(2));
 170       add2 = phase->transform(add2);
 171       set_req(1, add2);
 172       set_req(2, a12);
 173       progress = this;
 174       add2 = a12;
 175     }
 176   }
 177 
 178   // Convert "x+(y+1)" into "(x+y)+1".  Push constants down the expression tree.
 179   Opcodes add2_op = add2->Opcode();
 180   if( add2_op == this_op && !con_left ) {
 181     Node *a22 = add2->in(2);
 182     const Type *t22 = phase->type( a22 );
 183     if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&
 184        !(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) {
 185       assert(add2->in(1) != this, "dead loop in AddNode::Ideal");
 186       Node *addx = add2->clone();
 187       addx->set_req(1, in(1));
 188       addx->set_req(2, add2->in(1));
 189       addx = phase->transform(addx);
 190       set_req(1, addx);
 191       set_req(2, a22);
 192       progress = this;
 193       PhaseIterGVN *igvn = phase->is_IterGVN();
 194       if (add2->outcnt() == 0 && igvn) {
 195         // add disconnected.
 196         igvn->_worklist.push(add2);
 197       }
 198     }
 199   }


 223 
 224   return add_ring(t1,t2);               // Local flavor of type addition
 225 }
 226 
 227 //------------------------------add_identity-----------------------------------
 228 // Check for addition of the identity
 229 const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const {
 230   const Type *zero = add_id();  // The additive identity
 231   if( t1->higher_equal( zero ) ) return t2;
 232   if( t2->higher_equal( zero ) ) return t1;
 233 
 234   return NULL;
 235 }
 236 
 237 
 238 //=============================================================================
 239 //------------------------------Idealize---------------------------------------
 240 Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 241   Node* in1 = in(1);
 242   Node* in2 = in(2);
 243   Opcodes op1 = in1->Opcode();
 244   Opcodes op2 = in2->Opcode();
 245   // Fold (con1-x)+con2 into (con1+con2)-x
 246   if ( op1 == Opcodes::Op_AddI && op2 == Opcodes::Op_SubI ) {
 247     // Swap edges to try optimizations below
 248     in1 = in2;
 249     in2 = in(1);
 250     op1 = op2;
 251     op2 = in2->Opcode();
 252   }
 253   if( op1 == Opcodes::Op_SubI ) {
 254     const Type *t_sub1 = phase->type( in1->in(1) );
 255     const Type *t_2    = phase->type( in2        );
 256     if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
 257       return new SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
 258     // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
 259     if( op2 == Opcodes::Op_SubI ) {
 260       // Check for dead cycle: d = (a-b)+(c-d)
 261       assert( in1->in(2) != this && in2->in(2) != this,
 262               "dead loop in AddINode::Ideal" );
 263       Node *sub  = new SubINode(NULL, NULL);
 264       sub->init_req(1, phase->transform(new AddINode(in1->in(1), in2->in(1) ) ));
 265       sub->init_req(2, phase->transform(new AddINode(in1->in(2), in2->in(2) ) ));
 266       return sub;
 267     }
 268     // Convert "(a-b)+(b+c)" into "(a+c)"
 269     if( op2 == Opcodes::Op_AddI && in1->in(2) == in2->in(1) ) {
 270       assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
 271       return new AddINode(in1->in(1), in2->in(2));
 272     }
 273     // Convert "(a-b)+(c+b)" into "(a+c)"
 274     if( op2 == Opcodes::Op_AddI && in1->in(2) == in2->in(2) ) {
 275       assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
 276       return new AddINode(in1->in(1), in2->in(1));
 277     }
 278     // Convert "(a-b)+(b-c)" into "(a-c)"
 279     if( op2 == Opcodes::Op_SubI && in1->in(2) == in2->in(1) ) {
 280       assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
 281       return new SubINode(in1->in(1), in2->in(2));
 282     }
 283     // Convert "(a-b)+(c-a)" into "(c-b)"
 284     if( op2 == Opcodes::Op_SubI && in1->in(1) == in2->in(2) ) {
 285       assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
 286       return new SubINode(in2->in(1), in1->in(2));
 287     }
 288   }
 289 
 290   // Convert "x+(0-y)" into "(x-y)"
 291   if( op2 == Opcodes::Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
 292     return new SubINode(in1, in2->in(2) );
 293 
 294   // Convert "(0-y)+x" into "(x-y)"
 295   if( op1 == Opcodes::Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
 296     return new SubINode( in2, in1->in(2) );
 297 
 298   // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.
 299   // Helps with array allocation math constant folding
 300   // See 4790063:
 301   // Unrestricted transformation is unsafe for some runtime values of 'x'
 302   // ( x ==  0, z == 1, y == -1 ) fails
 303   // ( x == -5, z == 1, y ==  1 ) fails
 304   // Transform works for small z and small negative y when the addition
 305   // (x + (y << z)) does not cross zero.
 306   // Implement support for negative y and (x >= -(y << z))
 307   // Have not observed cases where type information exists to support
 308   // positive y and (x <= -(y << z))
 309   if( op1 == Opcodes::Op_URShiftI && op2 == Opcodes::Op_ConI &&
 310       in1->in(2)->Opcode() == Opcodes::Op_ConI ) {
 311     jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
 312     jint y = phase->type( in2 )->is_int()->get_con();
 313 
 314     if( z < 5 && -5 < y && y < 0 ) {
 315       const Type *t_in11 = phase->type(in1->in(1));
 316       if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
 317         Node *a = phase->transform( new AddINode( in1->in(1), phase->intcon(y<<z) ) );
 318         return new URShiftINode( a, in1->in(2) );
 319       }
 320     }
 321   }
 322 
 323   return AddNode::Ideal(phase, can_reshape);
 324 }
 325 
 326 
 327 //------------------------------Identity---------------------------------------
 328 // Fold (x-y)+y  OR  y+(x-y)  into  x
 329 Node* AddINode::Identity(PhaseGVN* phase) {
 330   if( in(1)->Opcode() == Opcodes::Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
 331     return in(1)->in(1);
 332   }
 333   else if( in(2)->Opcode() == Opcodes::Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
 334     return in(2)->in(1);
 335   }
 336   return AddNode::Identity(phase);
 337 }
 338 
 339 
 340 //------------------------------add_ring---------------------------------------
 341 // Supplied function returns the sum of the inputs.  Guaranteed never
 342 // to be passed a TOP or BOTTOM type, these are filtered out by
 343 // pre-check.
 344 const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {
 345   const TypeInt *r0 = t0->is_int(); // Handy access
 346   const TypeInt *r1 = t1->is_int();
 347   int lo = java_add(r0->_lo, r1->_lo);
 348   int hi = java_add(r0->_hi, r1->_hi);
 349   if( !(r0->is_con() && r1->is_con()) ) {
 350     // Not both constants, compute approximate result
 351     if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
 352       lo = min_jint; hi = max_jint; // Underflow on the low side
 353     }
 354     if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
 355       lo = min_jint; hi = max_jint; // Overflow on the high side
 356     }
 357     if( lo > hi ) {               // Handle overflow
 358       lo = min_jint; hi = max_jint;
 359     }
 360   } else {
 361     // both constants, compute precise result using 'lo' and 'hi'
 362     // Semantics define overflow and underflow for integer addition
 363     // as expected.  In particular: 0x80000000 + 0x80000000 --> 0x0
 364   }
 365   return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
 366 }
 367 
 368 
 369 //=============================================================================
 370 //------------------------------Idealize---------------------------------------
 371 Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 372   Node* in1 = in(1);
 373   Node* in2 = in(2);
 374   Opcodes op1 = in1->Opcode();
 375   Opcodes op2 = in2->Opcode();
 376   // Fold (con1-x)+con2 into (con1+con2)-x
 377   if ( op1 == Opcodes::Op_AddL && op2 == Opcodes::Op_SubL ) {
 378     // Swap edges to try optimizations below
 379     in1 = in2;
 380     in2 = in(1);
 381     op1 = op2;
 382     op2 = in2->Opcode();
 383   }
 384   // Fold (con1-x)+con2 into (con1+con2)-x
 385   if( op1 == Opcodes::Op_SubL ) {
 386     const Type *t_sub1 = phase->type( in1->in(1) );
 387     const Type *t_2    = phase->type( in2        );
 388     if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
 389       return new SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
 390     // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
 391     if( op2 == Opcodes::Op_SubL ) {
 392       // Check for dead cycle: d = (a-b)+(c-d)
 393       assert( in1->in(2) != this && in2->in(2) != this,
 394               "dead loop in AddLNode::Ideal" );
 395       Node *sub  = new SubLNode(NULL, NULL);
 396       sub->init_req(1, phase->transform(new AddLNode(in1->in(1), in2->in(1) ) ));
 397       sub->init_req(2, phase->transform(new AddLNode(in1->in(2), in2->in(2) ) ));
 398       return sub;
 399     }
 400     // Convert "(a-b)+(b+c)" into "(a+c)"
 401     if( op2 == Opcodes::Op_AddL && in1->in(2) == in2->in(1) ) {
 402       assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
 403       return new AddLNode(in1->in(1), in2->in(2));
 404     }
 405     // Convert "(a-b)+(c+b)" into "(a+c)"
 406     if( op2 == Opcodes::Op_AddL && in1->in(2) == in2->in(2) ) {
 407       assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
 408       return new AddLNode(in1->in(1), in2->in(1));
 409     }
 410     // Convert "(a-b)+(b-c)" into "(a-c)"
 411     if( op2 == Opcodes::Op_SubL && in1->in(2) == in2->in(1) ) {
 412       assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
 413       return new SubLNode(in1->in(1), in2->in(2));
 414     }
 415     // Convert "(a-b)+(c-a)" into "(c-b)"
 416     if( op2 == Opcodes::Op_SubL && in1->in(1) == in1->in(2) ) {
 417       assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
 418       return new SubLNode(in2->in(1), in1->in(2));
 419     }
 420   }
 421 
 422   // Convert "x+(0-y)" into "(x-y)"
 423   if( op2 == Opcodes::Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
 424     return new SubLNode( in1, in2->in(2) );
 425 
 426   // Convert "(0-y)+x" into "(x-y)"
 427   if( op1 == Opcodes::Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
 428     return new SubLNode( in2, in1->in(2) );
 429 
 430   // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
 431   // into "(X<<1)+Y" and let shift-folding happen.
 432   if( op2 == Opcodes::Op_AddL &&
 433       in2->in(1) == in1 &&
 434       op1 != Opcodes::Op_ConL &&
 435       0 ) {
 436     Node *shift = phase->transform(new LShiftLNode(in1,phase->intcon(1)));
 437     return new AddLNode(shift,in2->in(2));
 438   }
 439 
 440   return AddNode::Ideal(phase, can_reshape);
 441 }
 442 
 443 
 444 //------------------------------Identity---------------------------------------
 445 // Fold (x-y)+y  OR  y+(x-y)  into  x
 446 Node* AddLNode::Identity(PhaseGVN* phase) {
 447   if( in(1)->Opcode() == Opcodes::Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
 448     return in(1)->in(1);
 449   }
 450   else if( in(2)->Opcode() == Opcodes::Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
 451     return in(2)->in(1);
 452   }
 453   return AddNode::Identity(phase);
 454 }
 455 
 456 
 457 //------------------------------add_ring---------------------------------------
 458 // Supplied function returns the sum of the inputs.  Guaranteed never
 459 // to be passed a TOP or BOTTOM type, these are filtered out by
 460 // pre-check.
 461 const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {
 462   const TypeLong *r0 = t0->is_long(); // Handy access
 463   const TypeLong *r1 = t1->is_long();
 464   jlong lo = java_add(r0->_lo, r1->_lo);
 465   jlong hi = java_add(r0->_hi, r1->_hi);
 466   if( !(r0->is_con() && r1->is_con()) ) {
 467     // Not both constants, compute approximate result
 468     if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
 469       lo =min_jlong; hi = max_jlong; // Underflow on the low side
 470     }


 606         set_req(Offset,offset);
 607       }
 608       return this;
 609     }
 610   }
 611 
 612   // Raw pointers?
 613   if( in(Base)->bottom_type() == Type::TOP ) {
 614     // If this is a NULL+long form (from unsafe accesses), switch to a rawptr.
 615     if (phase->type(in(Address)) == TypePtr::NULL_PTR) {
 616       Node* offset = in(Offset);
 617       return new CastX2PNode(offset);
 618     }
 619   }
 620 
 621   // If the right is an add of a constant, push the offset down.
 622   // Convert: (ptr + (offset+con)) into (ptr+offset)+con.
 623   // The idea is to merge array_base+scaled_index groups together,
 624   // and only have different constant offsets from the same base.
 625   const Node *add = in(Offset);
 626   if( add->Opcode() == Opcodes::Op_AddX && add->in(1) != add ) {
 627     const Type *t22 = phase->type( add->in(2) );
 628     if( t22->singleton() && (t22 != Type::TOP) ) {  // Right input is an add of a constant?
 629       set_req(Address, phase->transform(new AddPNode(in(Base),in(Address),add->in(1))));
 630       set_req(Offset, add->in(2));
 631       PhaseIterGVN *igvn = phase->is_IterGVN();
 632       if (add->outcnt() == 0 && igvn) {
 633         // add disconnected.
 634         igvn->_worklist.push((Node*)add);
 635       }
 636       return this;              // Made progress
 637     }
 638   }
 639 
 640   return NULL;                  // No progress
 641 }
 642 
 643 //------------------------------bottom_type------------------------------------
 644 // Bottom-type is the pointer-type with unknown offset.
 645 const Type *AddPNode::bottom_type() const {
 646   if (in(Address) == NULL)  return TypePtr::BOTTOM;
 647   const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
 648   if( !tp ) return Type::TOP;   // TOP input means TOP output
 649   assert( in(Offset)->Opcode() != Opcodes::Op_ConP, "" );
 650   const Type *t = in(Offset)->bottom_type();
 651   if( t == Type::TOP )
 652     return tp->add_offset(Type::OffsetTop);
 653   const TypeX *tx = t->is_intptr_t();
 654   intptr_t txoffset = Type::OffsetBot;
 655   if (tx->is_con()) {   // Left input is an add of a constant?
 656     txoffset = tx->get_con();
 657   }
 658   return tp->add_offset(txoffset);
 659 }
 660 
 661 //------------------------------Value------------------------------------------
 662 const Type* AddPNode::Value(PhaseGVN* phase) const {
 663   // Either input is TOP ==> the result is TOP
 664   const Type *t1 = phase->type( in(Address) );
 665   const Type *t2 = phase->type( in(Offset) );
 666   if( t1 == Type::TOP ) return Type::TOP;
 667   if( t2 == Type::TOP ) return Type::TOP;
 668 
 669   // Left input is a pointer


 837 // Supplied function returns the sum of the inputs.
 838 const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const {
 839   const TypeInt *r0 = t0->is_int(); // Handy access
 840   const TypeInt *r1 = t1->is_int();
 841 
 842   // Otherwise just MAX them bits.
 843   return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
 844 }
 845 
 846 //=============================================================================
 847 //------------------------------Idealize---------------------------------------
 848 // MINs show up in range-check loop limit calculations.  Look for
 849 // "MIN2(x+c0,MIN2(y,x+c1))".  Pick the smaller constant: "MIN2(x+c0,y)"
 850 Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 851   Node *progress = NULL;
 852   // Force a right-spline graph
 853   Node *l = in(1);
 854   Node *r = in(2);
 855   // Transform  MinI1( MinI2(a,b), c)  into  MinI1( a, MinI2(b,c) )
 856   // to force a right-spline graph for the rest of MinINode::Ideal().
 857   if( l->Opcode() == Opcodes::Op_MinI ) {
 858     assert( l != l->in(1), "dead loop in MinINode::Ideal" );
 859     r = phase->transform(new MinINode(l->in(2),r));
 860     l = l->in(1);
 861     set_req(1, l);
 862     set_req(2, r);
 863     return this;
 864   }
 865 
 866   // Get left input & constant
 867   Node *x = l;
 868   int x_off = 0;
 869   if( x->Opcode() == Opcodes::Op_AddI && // Check for "x+c0" and collect constant
 870       x->in(2)->is_Con() ) {
 871     const Type *t = x->in(2)->bottom_type();
 872     if( t == Type::TOP ) return NULL;  // No progress
 873     x_off = t->is_int()->get_con();
 874     x = x->in(1);
 875   }
 876 
 877   // Scan a right-spline-tree for MINs
 878   Node *y = r;
 879   int y_off = 0;
 880   // Check final part of MIN tree
 881   if( y->Opcode() == Opcodes::Op_AddI && // Check for "y+c1" and collect constant
 882       y->in(2)->is_Con() ) {
 883     const Type *t = y->in(2)->bottom_type();
 884     if( t == Type::TOP ) return NULL;  // No progress
 885     y_off = t->is_int()->get_con();
 886     y = y->in(1);
 887   }
 888   if( x->_idx > y->_idx && r->Opcode() != Opcodes::Op_MinI ) {
 889     swap_edges(1, 2);
 890     return this;
 891   }
 892 
 893 
 894   if( r->Opcode() == Opcodes::Op_MinI ) {
 895     assert( r != r->in(2), "dead loop in MinINode::Ideal" );
 896     y = r->in(1);
 897     // Check final part of MIN tree
 898     if( y->Opcode() == Opcodes::Op_AddI &&// Check for "y+c1" and collect constant
 899         y->in(2)->is_Con() ) {
 900       const Type *t = y->in(2)->bottom_type();
 901       if( t == Type::TOP ) return NULL;  // No progress
 902       y_off = t->is_int()->get_con();
 903       y = y->in(1);
 904     }
 905 
 906     if( x->_idx > y->_idx )
 907       return new MinINode(r->in(1),phase->transform(new MinINode(l,r->in(2))));
 908 
 909     // See if covers: MIN2(x+c0,MIN2(y+c1,z))
 910     if( !phase->eqv(x,y) ) return NULL;
 911     // If (y == x) transform MIN2(x+c0, MIN2(x+c1,z)) into
 912     // MIN2(x+c0 or x+c1 which less, z).
 913     return new MinINode(phase->transform(new AddINode(x,phase->intcon(MIN2(x_off,y_off)))),r->in(2));
 914   } else {
 915     // See if covers: MIN2(x+c0,y+c1)
 916     if( !phase->eqv(x,y) ) return NULL;
 917     // If (y == x) transform MIN2(x+c0,x+c1) into x+c0 or x+c1 which less.
 918     return new AddINode(x,phase->intcon(MIN2(x_off,y_off)));
< prev index next >