src/share/vm/opto/addnode.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/addnode.cpp

Print this page
rev 9125 : 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
Summary: change ((x & m) u<= m) to always true and ((x & (m - 1)) u< m) into (m > 0)
Reviewed-by:


  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( PhaseTransform *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, int con_left, int 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;
  71   // Left is a constant; move it right.
  72   if( con_left ) {
  73     add->swap_edges(1, 2);
  74     return true;
  75   }
  76 
  77   // Convert "Load+x" into "x+Load".
  78   // Now check for loads
  79   if (in2->is_Load()) {
  80     if (!in1->is_Load()) {
  81       // already x+Load to return
  82       return false;
  83     }
  84     // both are loads, so fall through to sort inputs by idx


  93   if( in1->is_Phi() && (phi = in1->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add)
  94     return false;
  95   if( in2->is_Phi() && (phi = in2->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add){
  96     add->swap_edges(1, 2);
  97     return true;
  98   }
  99 
 100   // Otherwise, sort inputs (commutativity) to help value numbering.
 101   if( in1->_idx > in2->_idx ) {
 102     add->swap_edges(1, 2);
 103     return true;
 104   }
 105   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   int con_left  = t1->singleton();
 114   int 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




  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( PhaseTransform *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;
  71   // Left is a constant; move it right.
  72   if( con_left ) {
  73     add->swap_edges(1, 2);
  74     return true;
  75   }
  76 
  77   // Convert "Load+x" into "x+Load".
  78   // Now check for loads
  79   if (in2->is_Load()) {
  80     if (!in1->is_Load()) {
  81       // already x+Load to return
  82       return false;
  83     }
  84     // both are loads, so fall through to sort inputs by idx


  93   if( in1->is_Phi() && (phi = in1->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add)
  94     return false;
  95   if( in2->is_Phi() && (phi = in2->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add){
  96     add->swap_edges(1, 2);
  97     return true;
  98   }
  99 
 100   // Otherwise, sort inputs (commutativity) to help value numbering.
 101   if( in1->_idx > in2->_idx ) {
 102     add->swap_edges(1, 2);
 103     return true;
 104   }
 105   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


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