< prev index next >

src/share/vm/opto/mulnode.cpp

Print this page




 152     const Type *zero = add_id();        // The multiplicative zero
 153     if( t1->higher_equal( zero ) ) return zero;
 154     if( t2->higher_equal( zero ) ) return zero;
 155   }
 156 
 157   // Either input is BOTTOM ==> the result is the local BOTTOM
 158   if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
 159     return bottom_type();
 160 
 161 #if defined(IA32)
 162   // Can't trust native compilers to properly fold strict double
 163   // multiplication with round-to-zero on this platform.
 164   if (op == Op_MulD && phase->C->method()->is_strict()) {
 165     return TypeD::DOUBLE;
 166   }
 167 #endif
 168 
 169   return mul_ring(t1,t2);            // Local flavor of type multiplication
 170 }
 171 
 172 
 173 //=============================================================================
 174 //------------------------------Ideal------------------------------------------
 175 // Check for power-of-2 multiply, then try the regular MulNode::Ideal
 176 Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 177   // Swap constant to right
 178   jint con;
 179   if ((con = in(1)->find_int_con(0)) != 0) {
 180     swap_edges(1, 2);
 181     // Finish rest of method to use info in 'con'
 182   } else if ((con = in(2)->find_int_con(0)) == 0) {
 183     return MulNode::Ideal(phase, can_reshape);
 184   }
 185 
 186   // Now we have a constant Node on the right and the constant in con
 187   if( con == 0 ) return NULL;   // By zero is handled by Value call
 188   if( con == 1 ) return NULL;   // By one  is handled by Identity call
 189 
 190   // Check for negative constant; if so negate the final result
 191   bool sign_flip = false;
 192   if( con < 0 ) {
 193     con = -con;

 194     sign_flip = true;
 195   }
 196 
 197   // Get low bit; check for being the only bit
 198   Node *res = NULL;
 199   jint bit1 = con & -con;       // Extract low bit
 200   if( bit1 == con ) {           // Found a power of 2?
 201     res = new (phase->C) LShiftINode( in(1), phase->intcon(log2_intptr(bit1)) );
 202   } else {
 203 
 204     // Check for constant with 2 bits set
 205     jint bit2 = con-bit1;
 206     bit2 = bit2 & -bit2;          // Extract 2nd bit
 207     if( bit2 + bit1 == con ) {    // Found all bits in con?
 208       Node *n1 = phase->transform( new (phase->C) LShiftINode( in(1), phase->intcon(log2_intptr(bit1)) ) );
 209       Node *n2 = phase->transform( new (phase->C) LShiftINode( in(1), phase->intcon(log2_intptr(bit2)) ) );
 210       res = new (phase->C) AddINode( n2, n1 );
 211 
 212     } else if (is_power_of_2(con+1)) {
 213       // Sleezy: power-of-2 -1.  Next time be generic.
 214       jint temp = (jint) (con + 1);
 215       Node *n1 = phase->transform( new (phase->C) LShiftINode( in(1), phase->intcon(log2_intptr(temp)) ) );
 216       res = new (phase->C) SubINode( n1, in(1) );
 217     } else {
 218       return MulNode::Ideal(phase, can_reshape);
 219     }
 220   }
 221 
 222   if( sign_flip ) {             // Need to negate result?
 223     res = phase->transform(res);// Transform, before making the zero con
 224     res = new (phase->C) SubINode(phase->intcon(0),res);
 225   }
 226 
 227   return res;                   // Return final result
 228 }
 229 
 230 //------------------------------mul_ring---------------------------------------
 231 // Compute the product type of two integer ranges into this node.
 232 const Type *MulINode::mul_ring(const Type *t0, const Type *t1) const {
 233   const TypeInt *r0 = t0->is_int(); // Handy access
 234   const TypeInt *r1 = t1->is_int();
 235 
 236   // Fetch endpoints of all ranges
 237   int32 lo0 = r0->_lo;
 238   double a = (double)lo0;
 239   int32 hi0 = r0->_hi;
 240   double b = (double)hi0;
 241   int32 lo1 = r1->_lo;
 242   double c = (double)lo1;


 263     if( C > hi0 ) hi0 = C;
 264   }
 265   return TypeInt::make(lo0, hi0, MAX2(r0->_widen,r1->_widen));
 266 }
 267 
 268 
 269 //=============================================================================
 270 //------------------------------Ideal------------------------------------------
 271 // Check for power-of-2 multiply, then try the regular MulNode::Ideal
 272 Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 273   // Swap constant to right
 274   jlong con;
 275   if ((con = in(1)->find_long_con(0)) != 0) {
 276     swap_edges(1, 2);
 277     // Finish rest of method to use info in 'con'
 278   } else if ((con = in(2)->find_long_con(0)) == 0) {
 279     return MulNode::Ideal(phase, can_reshape);
 280   }
 281 
 282   // Now we have a constant Node on the right and the constant in con
 283   if( con == CONST64(0) ) return NULL;  // By zero is handled by Value call
 284   if( con == CONST64(1) ) return NULL;  // By one  is handled by Identity call
 285 
 286   // Check for negative constant; if so negate the final result
 287   bool sign_flip = false;
 288   if( con < 0 ) {
 289     con = -con;
 290     sign_flip = true;
 291   }
 292 
 293   // Get low bit; check for being the only bit
 294   Node *res = NULL;
 295   jlong bit1 = con & -con;      // Extract low bit
 296   if( bit1 == con ) {           // Found a power of 2?
 297     res = new (phase->C) LShiftLNode( in(1), phase->intcon(log2_long(bit1)) );
 298   } else {
 299 
 300     // Check for constant with 2 bits set
 301     jlong bit2 = con-bit1;
 302     bit2 = bit2 & -bit2;          // Extract 2nd bit
 303     if( bit2 + bit1 == con ) {    // Found all bits in con?
 304       Node *n1 = phase->transform( new (phase->C) LShiftLNode( in(1), phase->intcon(log2_long(bit1)) ) );
 305       Node *n2 = phase->transform( new (phase->C) LShiftLNode( in(1), phase->intcon(log2_long(bit2)) ) );
 306       res = new (phase->C) AddLNode( n2, n1 );
 307 
 308     } else if (is_power_of_2_long(con+1)) {
 309       // Sleezy: power-of-2 -1.  Next time be generic.
 310       jlong temp = (jlong) (con + 1);
 311       Node *n1 = phase->transform( new (phase->C) LShiftLNode( in(1), phase->intcon(log2_long(temp)) ) );
 312       res = new (phase->C) SubLNode( n1, in(1) );
 313     } else {
 314       return MulNode::Ideal(phase, can_reshape);
 315     }
 316   }
 317 
 318   if( sign_flip ) {             // Need to negate result?
 319     res = phase->transform(res);// Transform, before making the zero con
 320     res = new (phase->C) SubLNode(phase->longcon(0),res);
 321   }
 322 
 323   return res;                   // Return final result
 324 }
 325 
 326 //------------------------------mul_ring---------------------------------------
 327 // Compute the product type of two integer ranges into this node.
 328 const Type *MulLNode::mul_ring(const Type *t0, const Type *t1) const {
 329   const TypeLong *r0 = t0->is_long(); // Handy access
 330   const TypeLong *r1 = t1->is_long();
 331 
 332   // Fetch endpoints of all ranges
 333   jlong lo0 = r0->_lo;
 334   double a = (double)lo0;
 335   jlong hi0 = r0->_hi;
 336   double b = (double)hi0;
 337   jlong lo1 = r1->_lo;
 338   double c = (double)lo1;




 152     const Type *zero = add_id();        // The multiplicative zero
 153     if( t1->higher_equal( zero ) ) return zero;
 154     if( t2->higher_equal( zero ) ) return zero;
 155   }
 156 
 157   // Either input is BOTTOM ==> the result is the local BOTTOM
 158   if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
 159     return bottom_type();
 160 
 161 #if defined(IA32)
 162   // Can't trust native compilers to properly fold strict double
 163   // multiplication with round-to-zero on this platform.
 164   if (op == Op_MulD && phase->C->method()->is_strict()) {
 165     return TypeD::DOUBLE;
 166   }
 167 #endif
 168 
 169   return mul_ring(t1,t2);            // Local flavor of type multiplication
 170 }
 171 

 172 //=============================================================================
 173 //------------------------------Ideal------------------------------------------
 174 // Check for power-of-2 multiply, then try the regular MulNode::Ideal
 175 Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 176   // Swap constant to right
 177   jint con;
 178   if ((con = in(1)->find_int_con(0)) != 0) {
 179     swap_edges(1, 2);
 180     // Finish rest of method to use info in 'con'
 181   } else if ((con = in(2)->find_int_con(0)) == 0) {
 182     return MulNode::Ideal(phase, can_reshape);
 183   }
 184 
 185   // Now we have a constant Node on the right and the constant in con
 186   if (con == 0) return NULL;   // By zero is handled by Value call
 187   if (con == 1) return NULL;   // By one  is handled by Identity call
 188 
 189   // Check for negative constant; if so negate the final result
 190   bool sign_flip = false;
 191 
 192   unsigned int abs_con = uabs(con);
 193   if (abs_con != (unsigned int)con) {
 194     sign_flip = true;
 195   }
 196 
 197   // Get low bit; check for being the only bit
 198   Node *res = NULL;
 199   unsigned int bit1 = abs_con & (0-abs_con);       // Extract low bit
 200   if (bit1 == abs_con) {           // Found a power of 2?
 201     res = new (phase->C) LShiftINode(in(1), phase->intcon(log2_intptr(bit1)));
 202   } else {
 203 
 204     // Check for constant with 2 bits set
 205     unsigned int bit2 = abs_con-bit1;
 206     bit2 = bit2 & (0-bit2);          // Extract 2nd bit
 207     if (bit2 + bit1 == abs_con) {    // Found all bits in con?
 208       Node *n1 = phase->transform( new (phase->C) LShiftINode(in(1), phase->intcon(log2_intptr(bit1))));
 209       Node *n2 = phase->transform( new (phase->C) LShiftINode(in(1), phase->intcon(log2_intptr(bit2))));
 210       res = new (phase->C) AddINode(n2, n1);
 211 
 212     } else if (is_power_of_2(abs_con+1)) {
 213       // Sleezy: power-of-2 -1.  Next time be generic.
 214       unsigned int temp = abs_con + 1;
 215       Node *n1 = phase->transform(new (phase->C) LShiftINode(in(1), phase->intcon(log2_intptr(temp))));
 216       res = new (phase->C) SubINode(n1, in(1));
 217     } else {
 218       return MulNode::Ideal(phase, can_reshape);
 219     }
 220   }
 221 
 222   if (sign_flip) {             // Need to negate result?
 223     res = phase->transform(res);// Transform, before making the zero con
 224     res = new (phase->C) SubINode(phase->intcon(0),res);
 225   }
 226 
 227   return res;                   // Return final result
 228 }
 229 
 230 //------------------------------mul_ring---------------------------------------
 231 // Compute the product type of two integer ranges into this node.
 232 const Type *MulINode::mul_ring(const Type *t0, const Type *t1) const {
 233   const TypeInt *r0 = t0->is_int(); // Handy access
 234   const TypeInt *r1 = t1->is_int();
 235 
 236   // Fetch endpoints of all ranges
 237   int32 lo0 = r0->_lo;
 238   double a = (double)lo0;
 239   int32 hi0 = r0->_hi;
 240   double b = (double)hi0;
 241   int32 lo1 = r1->_lo;
 242   double c = (double)lo1;


 263     if( C > hi0 ) hi0 = C;
 264   }
 265   return TypeInt::make(lo0, hi0, MAX2(r0->_widen,r1->_widen));
 266 }
 267 
 268 
 269 //=============================================================================
 270 //------------------------------Ideal------------------------------------------
 271 // Check for power-of-2 multiply, then try the regular MulNode::Ideal
 272 Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 273   // Swap constant to right
 274   jlong con;
 275   if ((con = in(1)->find_long_con(0)) != 0) {
 276     swap_edges(1, 2);
 277     // Finish rest of method to use info in 'con'
 278   } else if ((con = in(2)->find_long_con(0)) == 0) {
 279     return MulNode::Ideal(phase, can_reshape);
 280   }
 281 
 282   // Now we have a constant Node on the right and the constant in con
 283   if (con == CONST64(0)) return NULL;  // By zero is handled by Value call
 284   if (con == CONST64(1)) return NULL;  // By one  is handled by Identity call
 285 
 286   // Check for negative constant; if so negate the final result
 287   bool sign_flip = false;
 288   unsigned long abs_con = uabs(con);
 289   if (abs_con != (unsigned long)con) {
 290     sign_flip = true;
 291   }
 292 
 293   // Get low bit; check for being the only bit
 294   Node *res = NULL;
 295   unsigned long bit1 = abs_con & (0-abs_con);      // Extract low bit
 296   if (bit1 == abs_con) {           // Found a power of 2?
 297     res = new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit1)));
 298   } else {
 299 
 300     // Check for constant with 2 bits set
 301     unsigned long bit2 = abs_con-bit1;
 302     bit2 = bit2 & (0-bit2);          // Extract 2nd bit
 303     if (bit2 + bit1 == abs_con) {    // Found all bits in con?
 304       Node *n1 = phase->transform(new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit1))));
 305       Node *n2 = phase->transform(new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit2))));
 306       res = new (phase->C) AddLNode(n2, n1);
 307 
 308     } else if (is_power_of_2_long(abs_con+1)) {
 309       // Sleezy: power-of-2 -1.  Next time be generic.
 310       unsigned long temp = abs_con + 1;
 311       Node *n1 = phase->transform( new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(temp))));
 312       res = new (phase->C) SubLNode(n1, in(1));
 313     } else {
 314       return MulNode::Ideal(phase, can_reshape);
 315     }
 316   }
 317 
 318   if (sign_flip) {             // Need to negate result?
 319     res = phase->transform(res);// Transform, before making the zero con
 320     res = new (phase->C) SubLNode(phase->longcon(0),res);
 321   }
 322 
 323   return res;                   // Return final result
 324 }
 325 
 326 //------------------------------mul_ring---------------------------------------
 327 // Compute the product type of two integer ranges into this node.
 328 const Type *MulLNode::mul_ring(const Type *t0, const Type *t1) const {
 329   const TypeLong *r0 = t0->is_long(); // Handy access
 330   const TypeLong *r1 = t1->is_long();
 331 
 332   // Fetch endpoints of all ranges
 333   jlong lo0 = r0->_lo;
 334   double a = (double)lo0;
 335   jlong hi0 = r0->_hi;
 336   double b = (double)hi0;
 337   jlong lo1 = r1->_lo;
 338   double c = (double)lo1;


< prev index next >