< prev index next >

src/hotspot/share/opto/mulnode.cpp

Print this page

 190   return progress;
 191 }
 192 
 193 //------------------------------Value-----------------------------------------
 194 const Type* MulNode::Value(PhaseGVN* phase) const {
 195   const Type *t1 = phase->type( in(1) );
 196   const Type *t2 = phase->type( in(2) );
 197   // Either input is TOP ==> the result is TOP
 198   if( t1 == Type::TOP ) return Type::TOP;
 199   if( t2 == Type::TOP ) return Type::TOP;
 200 
 201   // Either input is ZERO ==> the result is ZERO.
 202   // Not valid for floats or doubles since +0.0 * -0.0 --> +0.0
 203   int op = Opcode();
 204   if( op == Op_MulI || op == Op_AndI || op == Op_MulL || op == Op_AndL ) {
 205     const Type *zero = add_id();        // The multiplicative zero
 206     if( t1->higher_equal( zero ) ) return zero;
 207     if( t2->higher_equal( zero ) ) return zero;
 208   }
 209 












 210   // Either input is BOTTOM ==> the result is the local BOTTOM
 211   if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
 212     return bottom_type();
 213 
 214 #if defined(IA32)
 215   // Can't trust native compilers to properly fold strict double
 216   // multiplication with round-to-zero on this platform.
 217   if (op == Op_MulD) {
 218     return TypeD::DOUBLE;
 219   }
 220 #endif
 221 
 222   return mul_ring(t1,t2);            // Local flavor of type multiplication
 223 }
 224 
 225 //=============================================================================
 226 //------------------------------Ideal------------------------------------------
 227 // Check for power-of-2 multiply, then try the regular MulNode::Ideal
 228 Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 229   // Swap constant to right

 621     const TypeLong* t1 = phase->type( in(1) )->isa_long();
 622     if (t1 != NULL && t1->_lo >= 0) {
 623       int bit_count = log2i_graceful(t1->_hi) + 1;
 624       jlong t1_support = jlong(max_julong >> (BitsPerJavaLong - bit_count));
 625       if ((t1_support & con) == t1_support)
 626         return usr;
 627     }
 628     uint lop = usr->Opcode();
 629     // Masking off the high bits of a unsigned-shift-right is not
 630     // needed either.
 631     if( lop == Op_URShiftL ) {
 632       const TypeInt *t12 = phase->type( usr->in(2) )->isa_int();
 633       if( t12 && t12->is_con() ) {  // Shift is by a constant
 634         int shift = t12->get_con();
 635         shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
 636         jlong mask = max_julong >> shift;
 637         if( (mask&con) == mask )  // If AND is useless, skip it
 638           return usr;
 639       }
 640     }








 641   }
 642   return MulNode::Identity(phase);
 643 }
 644 
 645 //------------------------------Ideal------------------------------------------
 646 Node *AndLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 647   // Special case constant AND mask
 648   const TypeLong *t2 = phase->type( in(2) )->isa_long();
 649   if( !t2 || !t2->is_con() ) return MulNode::Ideal(phase, can_reshape);
 650   const jlong mask = t2->get_con();
 651 
 652   Node* in1 = in(1);
 653   uint op = in1->Opcode();
 654 
 655   // Are we masking a long that was converted from an int with a mask
 656   // that fits in 32-bits?  Commute them and use an AndINode.  Don't
 657   // convert masks which would cause a sign extension of the integer
 658   // value.  This check includes UI2L masks (0x00000000FFFFFFFF) which
 659   // would be optimized away later in Identity.
 660   if (op == Op_ConvI2L && (mask & UCONST64(0xFFFFFFFF80000000)) == 0) {

 190   return progress;
 191 }
 192 
 193 //------------------------------Value-----------------------------------------
 194 const Type* MulNode::Value(PhaseGVN* phase) const {
 195   const Type *t1 = phase->type( in(1) );
 196   const Type *t2 = phase->type( in(2) );
 197   // Either input is TOP ==> the result is TOP
 198   if( t1 == Type::TOP ) return Type::TOP;
 199   if( t2 == Type::TOP ) return Type::TOP;
 200 
 201   // Either input is ZERO ==> the result is ZERO.
 202   // Not valid for floats or doubles since +0.0 * -0.0 --> +0.0
 203   int op = Opcode();
 204   if( op == Op_MulI || op == Op_AndI || op == Op_MulL || op == Op_AndL ) {
 205     const Type *zero = add_id();        // The multiplicative zero
 206     if( t1->higher_equal( zero ) ) return zero;
 207     if( t2->higher_equal( zero ) ) return zero;
 208   }
 209 
 210   // Code pattern on return from a call that returns an __Value.  Can
 211   // be optimized away if the return value turns out to be an oop.
 212   if (op == Op_AndX &&
 213       in(1) != NULL &&
 214       in(1)->Opcode() == Op_CastP2X &&
 215       in(1)->in(1) != NULL &&
 216       phase->type(in(1)->in(1))->isa_oopptr() &&
 217       t2->isa_intptr_t()->_lo >= 0 &&
 218       t2->isa_intptr_t()->_hi <= MinObjAlignmentInBytesMask) {
 219     return add_id();
 220   }
 221 
 222   // Either input is BOTTOM ==> the result is the local BOTTOM
 223   if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
 224     return bottom_type();
 225 
 226 #if defined(IA32)
 227   // Can't trust native compilers to properly fold strict double
 228   // multiplication with round-to-zero on this platform.
 229   if (op == Op_MulD) {
 230     return TypeD::DOUBLE;
 231   }
 232 #endif
 233 
 234   return mul_ring(t1,t2);            // Local flavor of type multiplication
 235 }
 236 
 237 //=============================================================================
 238 //------------------------------Ideal------------------------------------------
 239 // Check for power-of-2 multiply, then try the regular MulNode::Ideal
 240 Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
 241   // Swap constant to right

 633     const TypeLong* t1 = phase->type( in(1) )->isa_long();
 634     if (t1 != NULL && t1->_lo >= 0) {
 635       int bit_count = log2i_graceful(t1->_hi) + 1;
 636       jlong t1_support = jlong(max_julong >> (BitsPerJavaLong - bit_count));
 637       if ((t1_support & con) == t1_support)
 638         return usr;
 639     }
 640     uint lop = usr->Opcode();
 641     // Masking off the high bits of a unsigned-shift-right is not
 642     // needed either.
 643     if( lop == Op_URShiftL ) {
 644       const TypeInt *t12 = phase->type( usr->in(2) )->isa_int();
 645       if( t12 && t12->is_con() ) {  // Shift is by a constant
 646         int shift = t12->get_con();
 647         shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
 648         jlong mask = max_julong >> shift;
 649         if( (mask&con) == mask )  // If AND is useless, skip it
 650           return usr;
 651       }
 652     }
 653 
 654     // Check if this is part of an inline type test
 655     if (con == markWord::inline_type_pattern && in(1)->is_Load() &&
 656         phase->type(in(1)->in(MemNode::Address))->is_inlinetypeptr() &&
 657         phase->type(in(1)->in(MemNode::Address))->is_ptr()->offset() == oopDesc::mark_offset_in_bytes()) {
 658       assert(EnableValhalla, "should only be used for inline types");
 659       return in(2); // Obj is known to be an inline type
 660     }
 661   }
 662   return MulNode::Identity(phase);
 663 }
 664 
 665 //------------------------------Ideal------------------------------------------
 666 Node *AndLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 667   // Special case constant AND mask
 668   const TypeLong *t2 = phase->type( in(2) )->isa_long();
 669   if( !t2 || !t2->is_con() ) return MulNode::Ideal(phase, can_reshape);
 670   const jlong mask = t2->get_con();
 671 
 672   Node* in1 = in(1);
 673   uint op = in1->Opcode();
 674 
 675   // Are we masking a long that was converted from an int with a mask
 676   // that fits in 32-bits?  Commute them and use an AndINode.  Don't
 677   // convert masks which would cause a sign extension of the integer
 678   // value.  This check includes UI2L masks (0x00000000FFFFFFFF) which
 679   // would be optimized away later in Identity.
 680   if (op == Op_ConvI2L && (mask & UCONST64(0xFFFFFFFF80000000)) == 0) {
< prev index next >