< prev index next >

src/share/vm/opto/mulnode.cpp

Print this page




 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;
 243   int32 hi1 = r1->_hi;
 244   double d = (double)hi1;
 245 
 246   // Compute all endpoints & check for overflow
 247   int32 A = lo0*lo1;
 248   if( (double)A != a*c ) return TypeInt::INT; // Overflow?
 249   int32 B = lo0*hi1;
 250   if( (double)B != a*d ) return TypeInt::INT; // Overflow?
 251   int32 C = hi0*lo1;
 252   if( (double)C != b*c ) return TypeInt::INT; // Overflow?
 253   int32 D = hi0*hi1;
 254   if( (double)D != b*d ) return TypeInt::INT; // Overflow?
 255 
 256   if( A < B ) { lo0 = A; hi0 = B; } // Sort range endpoints
 257   else { lo0 = B; hi0 = A; }
 258   if( C < D ) {
 259     if( C < lo0 ) lo0 = C;
 260     if( D > hi0 ) hi0 = D;
 261   } else {
 262     if( D < lo0 ) lo0 = D;
 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


 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;
 339   jlong hi1 = r1->_hi;
 340   double d = (double)hi1;
 341 
 342   // Compute all endpoints & check for overflow
 343   jlong A = lo0*lo1;
 344   if( (double)A != a*c ) return TypeLong::LONG; // Overflow?
 345   jlong B = lo0*hi1;
 346   if( (double)B != a*d ) return TypeLong::LONG; // Overflow?
 347   jlong C = hi0*lo1;
 348   if( (double)C != b*c ) return TypeLong::LONG; // Overflow?
 349   jlong D = hi0*hi1;
 350   if( (double)D != b*d ) return TypeLong::LONG; // Overflow?
 351 
 352   if( A < B ) { lo0 = A; hi0 = B; } // Sort range endpoints
 353   else { lo0 = B; hi0 = A; }
 354   if( C < D ) {
 355     if( C < lo0 ) lo0 = C;
 356     if( D > hi0 ) hi0 = D;
 357   } else {
 358     if( D < lo0 ) lo0 = D;
 359     if( C > hi0 ) hi0 = C;
 360   }
 361   return TypeLong::make(lo0, hi0, MAX2(r0->_widen,r1->_widen));
 362 }
 363 
 364 //=============================================================================
 365 //------------------------------mul_ring---------------------------------------
 366 // Compute the product type of two double ranges into this node.
 367 const Type *MulFNode::mul_ring(const Type *t0, const Type *t1) const {
 368   if( t0 == Type::FLOAT || t1 == Type::FLOAT ) return Type::FLOAT;
 369   return TypeF::make( t0->getf() * t1->getf() );


 556   if( r1->is_con() && r1->get_con() > 0 )
 557     return TypeLong::make(CONST64(0), r1->get_con(), widen);
 558 
 559   return TypeLong::LONG;        // No constants to be had
 560 }
 561 
 562 //------------------------------Identity---------------------------------------
 563 // Masking off the high bits of an unsigned load is not required
 564 Node *AndLNode::Identity( PhaseTransform *phase ) {
 565 
 566   // x & x => x
 567   if (phase->eqv(in(1), in(2))) return in(1);
 568 
 569   Node *usr = in(1);
 570   const TypeLong *t2 = phase->type( in(2) )->isa_long();
 571   if( t2 && t2->is_con() ) {
 572     jlong con = t2->get_con();
 573     // Masking off high bits which are always zero is useless.
 574     const TypeLong* t1 = phase->type( in(1) )->isa_long();
 575     if (t1 != NULL && t1->_lo >= 0) {
 576       jlong t1_support = ((jlong)1 << (1 + log2_long(t1->_hi))) - 1;

 577       if ((t1_support & con) == t1_support)
 578         return usr;
 579     }
 580     uint lop = usr->Opcode();
 581     // Masking off the high bits of a unsigned-shift-right is not
 582     // needed either.
 583     if( lop == Op_URShiftL ) {
 584       const TypeInt *t12 = phase->type( usr->in(2) )->isa_int();
 585       if( t12 && t12->is_con() ) {  // Shift is by a constant
 586         int shift = t12->get_con();
 587         shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
 588         jlong mask = max_julong >> shift;
 589         if( (mask&con) == mask )  // If AND is useless, skip it
 590           return usr;
 591       }
 592     }
 593   }
 594   return MulNode::Identity(phase);
 595 }
 596 


 784   // Check for "(x>>c0)<<c0" which just masks off low bits
 785   if( (add1_op == Op_RShiftL || add1_op == Op_URShiftL ) &&
 786       add1->in(2) == in(2) )
 787     // Convert to "(x & -(1<<c0))"
 788     return new (phase->C) AndLNode(add1->in(1),phase->longcon( -(CONST64(1)<<con)));
 789 
 790   // Check for "((x>>c0) & Y)<<c0" which just masks off more low bits
 791   if( add1_op == Op_AndL ) {
 792     Node *add2 = add1->in(1);
 793     int add2_op = add2->Opcode();
 794     if( (add2_op == Op_RShiftL || add2_op == Op_URShiftL ) &&
 795         add2->in(2) == in(2) ) {
 796       // Convert to "(x & (Y<<c0))"
 797       Node *y_sh = phase->transform( new (phase->C) LShiftLNode( add1->in(2), in(2) ) );
 798       return new (phase->C) AndLNode( add2->in(1), y_sh );
 799     }
 800   }
 801 
 802   // Check for ((x & ((CONST64(1)<<(64-c0))-1)) << c0) which ANDs off high bits
 803   // before shifting them away.
 804   const jlong bits_mask = ((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - con)) - CONST64(1);
 805   if( add1_op == Op_AndL &&
 806       phase->type(add1->in(2)) == TypeLong::make( bits_mask ) )
 807     return new (phase->C) LShiftLNode( add1->in(1), in(2) );
 808 
 809   return NULL;
 810 }
 811 
 812 //------------------------------Value------------------------------------------
 813 // A LShiftLNode shifts its input2 left by input1 amount.
 814 const Type *LShiftLNode::Value( PhaseTransform *phase ) const {
 815   const Type *t1 = phase->type( in(1) );
 816   const Type *t2 = phase->type( in(2) );
 817   // Either input is TOP ==> the result is TOP
 818   if( t1 == Type::TOP ) return Type::TOP;
 819   if( t2 == Type::TOP ) return Type::TOP;
 820 
 821   // Left input is ZERO ==> the result is ZERO.
 822   if( t1 == TypeLong::ZERO ) return TypeLong::ZERO;
 823   // Shift by zero does nothing
 824   if( t2 == TypeInt::ZERO ) return t1;


1236   // }
1237 
1238   return TypeInt::INT;
1239 }
1240 
1241 //=============================================================================
1242 //------------------------------Identity---------------------------------------
1243 Node *URShiftLNode::Identity( PhaseTransform *phase ) {
1244   const TypeInt *ti = phase->type( in(2) )->isa_int(); // shift count is an int
1245   return ( ti && ti->is_con() && ( ti->get_con() & ( BitsPerLong - 1 ) ) == 0 ) ? in(1) : this;
1246 }
1247 
1248 //------------------------------Ideal------------------------------------------
1249 Node *URShiftLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1250   const TypeInt *t2 = phase->type( in(2) )->isa_int();
1251   if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant
1252   const int con = t2->get_con() & ( BitsPerLong - 1 ); // Shift count is always masked
1253   if ( con == 0 ) return NULL;  // let Identity() handle a 0 shift count
1254                               // note: mask computation below does not work for 0 shift count
1255   // We'll be wanting the right-shift amount as a mask of that many bits
1256   const jlong mask = (((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - con)) -1);
1257 
1258   // Check for ((x << z) + Y) >>> z.  Replace with x + con>>>z
1259   // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z".
1260   // If Q is "X << z" the rounding is useless.  Look for patterns like
1261   // ((X<<Z) + Y) >>> Z  and replace with (X + Y>>>Z) & Z-mask.
1262   Node *add = in(1);
1263   if( add->Opcode() == Op_AddL ) {
1264     Node *lshl = add->in(1);
1265     if( lshl->Opcode() == Op_LShiftL &&
1266         phase->type(lshl->in(2)) == t2 ) {
1267       Node *y_z = phase->transform( new (phase->C) URShiftLNode(add->in(2),in(2)) );
1268       Node *sum = phase->transform( new (phase->C) AddLNode( lshl->in(1), y_z ) );
1269       return new (phase->C) AndLNode( sum, phase->longcon(mask) );
1270     }
1271   }
1272 
1273   // Check for (x & mask) >>> z.  Replace with (x >>> z) & (mask >>> z)
1274   // This shortens the mask.  Also, if we are extracting a high byte and
1275   // storing it to a buffer, the mask will be removed completely.
1276   Node *andi = in(1);




 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;
 243   int32 hi1 = r1->_hi;
 244   double d = (double)hi1;
 245 
 246   // Compute all endpoints & check for overflow
 247   int32 A = java_multiply(lo0, lo1);
 248   if( (double)A != a*c ) return TypeInt::INT; // Overflow?
 249   int32 B = java_multiply(lo0, hi1);
 250   if( (double)B != a*d ) return TypeInt::INT; // Overflow?
 251   int32 C = java_multiply(hi0, lo1);
 252   if( (double)C != b*c ) return TypeInt::INT; // Overflow?
 253   int32 D = java_multiply(hi0, hi1);
 254   if( (double)D != b*d ) return TypeInt::INT; // Overflow?
 255 
 256   if( A < B ) { lo0 = A; hi0 = B; } // Sort range endpoints
 257   else { lo0 = B; hi0 = A; }
 258   if( C < D ) {
 259     if( C < lo0 ) lo0 = C;
 260     if( D > hi0 ) hi0 = D;
 261   } else {
 262     if( D < lo0 ) lo0 = D;
 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


 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;
 339   jlong hi1 = r1->_hi;
 340   double d = (double)hi1;
 341 
 342   // Compute all endpoints & check for overflow
 343   jlong A = java_multiply(lo0, lo1);
 344   if( (double)A != a*c ) return TypeLong::LONG; // Overflow?
 345   jlong B = java_multiply(lo0, hi1);
 346   if( (double)B != a*d ) return TypeLong::LONG; // Overflow?
 347   jlong C = java_multiply(hi0, lo1);
 348   if( (double)C != b*c ) return TypeLong::LONG; // Overflow?
 349   jlong D = java_multiply(hi0, hi1);
 350   if( (double)D != b*d ) return TypeLong::LONG; // Overflow?
 351 
 352   if( A < B ) { lo0 = A; hi0 = B; } // Sort range endpoints
 353   else { lo0 = B; hi0 = A; }
 354   if( C < D ) {
 355     if( C < lo0 ) lo0 = C;
 356     if( D > hi0 ) hi0 = D;
 357   } else {
 358     if( D < lo0 ) lo0 = D;
 359     if( C > hi0 ) hi0 = C;
 360   }
 361   return TypeLong::make(lo0, hi0, MAX2(r0->_widen,r1->_widen));
 362 }
 363 
 364 //=============================================================================
 365 //------------------------------mul_ring---------------------------------------
 366 // Compute the product type of two double ranges into this node.
 367 const Type *MulFNode::mul_ring(const Type *t0, const Type *t1) const {
 368   if( t0 == Type::FLOAT || t1 == Type::FLOAT ) return Type::FLOAT;
 369   return TypeF::make( t0->getf() * t1->getf() );


 556   if( r1->is_con() && r1->get_con() > 0 )
 557     return TypeLong::make(CONST64(0), r1->get_con(), widen);
 558 
 559   return TypeLong::LONG;        // No constants to be had
 560 }
 561 
 562 //------------------------------Identity---------------------------------------
 563 // Masking off the high bits of an unsigned load is not required
 564 Node *AndLNode::Identity( PhaseTransform *phase ) {
 565 
 566   // x & x => x
 567   if (phase->eqv(in(1), in(2))) return in(1);
 568 
 569   Node *usr = in(1);
 570   const TypeLong *t2 = phase->type( in(2) )->isa_long();
 571   if( t2 && t2->is_con() ) {
 572     jlong con = t2->get_con();
 573     // Masking off high bits which are always zero is useless.
 574     const TypeLong* t1 = phase->type( in(1) )->isa_long();
 575     if (t1 != NULL && t1->_lo >= 0) {
 576       int bit_count = log2_long(t1->_hi) + 1;
 577       jlong t1_support = jlong(max_julong >> (BitsPerJavaLong - bit_count));
 578       if ((t1_support & con) == t1_support)
 579         return usr;
 580     }
 581     uint lop = usr->Opcode();
 582     // Masking off the high bits of a unsigned-shift-right is not
 583     // needed either.
 584     if( lop == Op_URShiftL ) {
 585       const TypeInt *t12 = phase->type( usr->in(2) )->isa_int();
 586       if( t12 && t12->is_con() ) {  // Shift is by a constant
 587         int shift = t12->get_con();
 588         shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
 589         jlong mask = max_julong >> shift;
 590         if( (mask&con) == mask )  // If AND is useless, skip it
 591           return usr;
 592       }
 593     }
 594   }
 595   return MulNode::Identity(phase);
 596 }
 597 


 785   // Check for "(x>>c0)<<c0" which just masks off low bits
 786   if( (add1_op == Op_RShiftL || add1_op == Op_URShiftL ) &&
 787       add1->in(2) == in(2) )
 788     // Convert to "(x & -(1<<c0))"
 789     return new (phase->C) AndLNode(add1->in(1),phase->longcon( -(CONST64(1)<<con)));
 790 
 791   // Check for "((x>>c0) & Y)<<c0" which just masks off more low bits
 792   if( add1_op == Op_AndL ) {
 793     Node *add2 = add1->in(1);
 794     int add2_op = add2->Opcode();
 795     if( (add2_op == Op_RShiftL || add2_op == Op_URShiftL ) &&
 796         add2->in(2) == in(2) ) {
 797       // Convert to "(x & (Y<<c0))"
 798       Node *y_sh = phase->transform( new (phase->C) LShiftLNode( add1->in(2), in(2) ) );
 799       return new (phase->C) AndLNode( add2->in(1), y_sh );
 800     }
 801   }
 802 
 803   // Check for ((x & ((CONST64(1)<<(64-c0))-1)) << c0) which ANDs off high bits
 804   // before shifting them away.
 805   const jlong bits_mask = jlong(max_julong >> con);
 806   if( add1_op == Op_AndL &&
 807       phase->type(add1->in(2)) == TypeLong::make( bits_mask ) )
 808     return new (phase->C) LShiftLNode( add1->in(1), in(2) );
 809 
 810   return NULL;
 811 }
 812 
 813 //------------------------------Value------------------------------------------
 814 // A LShiftLNode shifts its input2 left by input1 amount.
 815 const Type *LShiftLNode::Value( PhaseTransform *phase ) const {
 816   const Type *t1 = phase->type( in(1) );
 817   const Type *t2 = phase->type( in(2) );
 818   // Either input is TOP ==> the result is TOP
 819   if( t1 == Type::TOP ) return Type::TOP;
 820   if( t2 == Type::TOP ) return Type::TOP;
 821 
 822   // Left input is ZERO ==> the result is ZERO.
 823   if( t1 == TypeLong::ZERO ) return TypeLong::ZERO;
 824   // Shift by zero does nothing
 825   if( t2 == TypeInt::ZERO ) return t1;


1237   // }
1238 
1239   return TypeInt::INT;
1240 }
1241 
1242 //=============================================================================
1243 //------------------------------Identity---------------------------------------
1244 Node *URShiftLNode::Identity( PhaseTransform *phase ) {
1245   const TypeInt *ti = phase->type( in(2) )->isa_int(); // shift count is an int
1246   return ( ti && ti->is_con() && ( ti->get_con() & ( BitsPerLong - 1 ) ) == 0 ) ? in(1) : this;
1247 }
1248 
1249 //------------------------------Ideal------------------------------------------
1250 Node *URShiftLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1251   const TypeInt *t2 = phase->type( in(2) )->isa_int();
1252   if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant
1253   const int con = t2->get_con() & ( BitsPerLong - 1 ); // Shift count is always masked
1254   if ( con == 0 ) return NULL;  // let Identity() handle a 0 shift count
1255                               // note: mask computation below does not work for 0 shift count
1256   // We'll be wanting the right-shift amount as a mask of that many bits
1257   const jlong mask = jlong(max_julong >> con);
1258 
1259   // Check for ((x << z) + Y) >>> z.  Replace with x + con>>>z
1260   // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z".
1261   // If Q is "X << z" the rounding is useless.  Look for patterns like
1262   // ((X<<Z) + Y) >>> Z  and replace with (X + Y>>>Z) & Z-mask.
1263   Node *add = in(1);
1264   if( add->Opcode() == Op_AddL ) {
1265     Node *lshl = add->in(1);
1266     if( lshl->Opcode() == Op_LShiftL &&
1267         phase->type(lshl->in(2)) == t2 ) {
1268       Node *y_z = phase->transform( new (phase->C) URShiftLNode(add->in(2),in(2)) );
1269       Node *sum = phase->transform( new (phase->C) AddLNode( lshl->in(1), y_z ) );
1270       return new (phase->C) AndLNode( sum, phase->longcon(mask) );
1271     }
1272   }
1273 
1274   // Check for (x & mask) >>> z.  Replace with (x >>> z) & (mask >>> z)
1275   // This shortens the mask.  Also, if we are extracting a high byte and
1276   // storing it to a buffer, the mask will be removed completely.
1277   Node *andi = in(1);


< prev index next >