< prev index next >

src/hotspot/share/opto/subnode.cpp

Print this page




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/addnode.hpp"
  29 #include "opto/callnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/loopnode.hpp"
  32 #include "opto/matcher.hpp"
  33 #include "opto/movenode.hpp"
  34 #include "opto/mulnode.hpp"
  35 #include "opto/opcodes.hpp"
  36 #include "opto/phaseX.hpp"
  37 #include "opto/subnode.hpp"
  38 #include "runtime/sharedRuntime.hpp"




  39 
  40 // Portions of code courtesy of Clifford Click
  41 
  42 // Optimization - Graph Style
  43 
  44 #include "math.h"
  45 
  46 //=============================================================================
  47 //------------------------------Identity---------------------------------------
  48 // If right input is a constant 0, return the left input.
  49 Node* SubNode::Identity(PhaseGVN* phase) {
  50   assert(in(1) != this, "Must already have called Value");
  51   assert(in(2) != this, "Must already have called Value");
  52 
  53   // Remove double negation
  54   const Type *zero = add_id();
  55   if( phase->type( in(1) )->higher_equal( zero ) &&
  56       in(2)->Opcode() == Opcode() &&
  57       phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
  58     return in(2)->in(2);


 863 
 864   // Known constants can be compared exactly
 865   // Null can be distinguished from any NotNull pointers
 866   // Unknown inputs makes an unknown result
 867   if( r0->singleton() ) {
 868     intptr_t bits0 = r0->get_con();
 869     if( r1->singleton() )
 870       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
 871     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
 872   } else if( r1->singleton() ) {
 873     intptr_t bits1 = r1->get_con();
 874     return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
 875   } else
 876     return TypeInt::CC;
 877 }
 878 
 879 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
 880   // Return the klass node for (indirect load from OopHandle)
 881   //   LoadP(LoadP(AddP(foo:Klass, #java_mirror)))
 882   //   or NULL if not matching.





 883   if (n->Opcode() != Op_LoadP) return NULL;
 884 
 885   const TypeInstPtr* tp = phase->type(n)->isa_instptr();
 886   if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
 887 
 888   Node* adr = n->in(MemNode::Address);
 889   // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier.
 890   if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return NULL;
 891   adr = adr->in(MemNode::Address);
 892 
 893   intptr_t off = 0;
 894   Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
 895   if (k == NULL)  return NULL;
 896   const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
 897   if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
 898 
 899   // We've found the klass node of a Java mirror load.
 900   return k;
 901 }
 902 


 915 
 916   // x.getClass() == int.class can never be true (for all primitive types)
 917   // Return a ConP(NULL) node for this case.
 918   if (mirror_type->is_classless()) {
 919     return phase->makecon(TypePtr::NULL_PTR);
 920   }
 921 
 922   // return the ConP(Foo.klass)
 923   assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
 924   return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass()));
 925 }
 926 
 927 //------------------------------Ideal------------------------------------------
 928 // Normalize comparisons between Java mirror loads to compare the klass instead.
 929 //
 930 // Also check for the case of comparing an unknown klass loaded from the primary
 931 // super-type array vs a known klass with no subtypes.  This amounts to
 932 // checking to see an unknown klass subtypes a known klass with no subtypes;
 933 // this only happens on an exact match.  We can shorten this test by 1 load.
 934 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {































 935   // Normalize comparisons between Java mirrors into comparisons of the low-
 936   // level klass, where a dependent load could be shortened.
 937   //
 938   // The new pattern has a nice effect of matching the same pattern used in the
 939   // fast path of instanceof/checkcast/Class.isInstance(), which allows
 940   // redundant exact type check be optimized away by GVN.
 941   // For example, in
 942   //   if (x.getClass() == Foo.class) {
 943   //     Foo foo = (Foo) x;
 944   //     // ... use a ...
 945   //   }
 946   // a CmpPNode could be shared between if_acmpne and checkcast
 947   {
 948     Node* k1 = isa_java_mirror_load(phase, in(1));
 949     Node* k2 = isa_java_mirror_load(phase, in(2));
 950     Node* conk2 = isa_const_java_mirror(phase, in(2));
 951 
 952     if (k1 && (k2 || conk2)) {
 953       Node* lhs = k1;
 954       Node* rhs = (k2 != NULL) ? k2 : conk2;
 955       this->set_req(1, lhs);
 956       this->set_req(2, rhs);









 957       return this;
 958     }
 959   }
 960 
 961   // Constant pointer on right?
 962   const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
 963   if (t2 == NULL || !t2->klass_is_exact())
 964     return NULL;
 965   // Get the constant klass we are comparing to.
 966   ciKlass* superklass = t2->klass();
 967 
 968   // Now check for LoadKlass on left.
 969   Node* ldk1 = in(1);
 970   if (ldk1->is_DecodeNKlass()) {
 971     ldk1 = ldk1->in(1);
 972     if (ldk1->Opcode() != Op_LoadNKlass )
 973       return NULL;
 974   } else if (ldk1->Opcode() != Op_LoadKlass )
 975     return NULL;
 976   // Take apart the address of the LoadKlass:




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/addnode.hpp"
  29 #include "opto/callnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/loopnode.hpp"
  32 #include "opto/matcher.hpp"
  33 #include "opto/movenode.hpp"
  34 #include "opto/mulnode.hpp"
  35 #include "opto/opcodes.hpp"
  36 #include "opto/phaseX.hpp"
  37 #include "opto/subnode.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 #include "utilities/macros.hpp"
  40 #if INCLUDE_SHENANDOAHGC
  41 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  42 #endif
  43 
  44 // Portions of code courtesy of Clifford Click
  45 
  46 // Optimization - Graph Style
  47 
  48 #include "math.h"
  49 
  50 //=============================================================================
  51 //------------------------------Identity---------------------------------------
  52 // If right input is a constant 0, return the left input.
  53 Node* SubNode::Identity(PhaseGVN* phase) {
  54   assert(in(1) != this, "Must already have called Value");
  55   assert(in(2) != this, "Must already have called Value");
  56 
  57   // Remove double negation
  58   const Type *zero = add_id();
  59   if( phase->type( in(1) )->higher_equal( zero ) &&
  60       in(2)->Opcode() == Opcode() &&
  61       phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
  62     return in(2)->in(2);


 867 
 868   // Known constants can be compared exactly
 869   // Null can be distinguished from any NotNull pointers
 870   // Unknown inputs makes an unknown result
 871   if( r0->singleton() ) {
 872     intptr_t bits0 = r0->get_con();
 873     if( r1->singleton() )
 874       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
 875     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
 876   } else if( r1->singleton() ) {
 877     intptr_t bits1 = r1->get_con();
 878     return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
 879   } else
 880     return TypeInt::CC;
 881 }
 882 
 883 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
 884   // Return the klass node for (indirect load from OopHandle)
 885   //   LoadP(LoadP(AddP(foo:Klass, #java_mirror)))
 886   //   or NULL if not matching.
 887 
 888 #if INCLUDE_SHENANDOAHGC
 889   n = ShenandoahBarrierNode::skip_through_barrier(n);
 890 #endif
 891 
 892   if (n->Opcode() != Op_LoadP) return NULL;
 893 
 894   const TypeInstPtr* tp = phase->type(n)->isa_instptr();
 895   if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
 896 
 897   Node* adr = n->in(MemNode::Address);
 898   // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier.
 899   if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return NULL;
 900   adr = adr->in(MemNode::Address);
 901 
 902   intptr_t off = 0;
 903   Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
 904   if (k == NULL)  return NULL;
 905   const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
 906   if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
 907 
 908   // We've found the klass node of a Java mirror load.
 909   return k;
 910 }
 911 


 924 
 925   // x.getClass() == int.class can never be true (for all primitive types)
 926   // Return a ConP(NULL) node for this case.
 927   if (mirror_type->is_classless()) {
 928     return phase->makecon(TypePtr::NULL_PTR);
 929   }
 930 
 931   // return the ConP(Foo.klass)
 932   assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
 933   return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass()));
 934 }
 935 
 936 //------------------------------Ideal------------------------------------------
 937 // Normalize comparisons between Java mirror loads to compare the klass instead.
 938 //
 939 // Also check for the case of comparing an unknown klass loaded from the primary
 940 // super-type array vs a known klass with no subtypes.  This amounts to
 941 // checking to see an unknown klass subtypes a known klass with no subtypes;
 942 // this only happens on an exact match.  We can shorten this test by 1 load.
 943 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
 944 #if INCLUDE_SHENANDOAHGC
 945   if (UseShenandoahGC) {
 946     Node* in1 = in(1);
 947     Node* in2 = in(2);
 948     if (in1->bottom_type() == TypePtr::NULL_PTR) {
 949       in2 = ShenandoahBarrierNode::skip_through_barrier(in2);
 950     }
 951     if (in2->bottom_type() == TypePtr::NULL_PTR) {
 952       in1 = ShenandoahBarrierNode::skip_through_barrier(in1);
 953     }
 954     PhaseIterGVN* igvn = phase->is_IterGVN();
 955     if (in1 != in(1)) {
 956       if (igvn != NULL) {
 957         set_req_X(1, in1, igvn);
 958       } else {
 959         set_req(1, in1);
 960       }
 961       assert(in2 == in(2), "only one change");
 962       return this;
 963     }
 964     if (in2 != in(2)) {
 965       if (igvn != NULL) {
 966         set_req_X(2, in2, igvn);
 967       } else {
 968         set_req(2, in2);
 969       }
 970       return this;
 971     }
 972   }
 973 #endif
 974 
 975   // Normalize comparisons between Java mirrors into comparisons of the low-
 976   // level klass, where a dependent load could be shortened.
 977   //
 978   // The new pattern has a nice effect of matching the same pattern used in the
 979   // fast path of instanceof/checkcast/Class.isInstance(), which allows
 980   // redundant exact type check be optimized away by GVN.
 981   // For example, in
 982   //   if (x.getClass() == Foo.class) {
 983   //     Foo foo = (Foo) x;
 984   //     // ... use a ...
 985   //   }
 986   // a CmpPNode could be shared between if_acmpne and checkcast
 987   {
 988     Node* k1 = isa_java_mirror_load(phase, in(1));
 989     Node* k2 = isa_java_mirror_load(phase, in(2));
 990     Node* conk2 = isa_const_java_mirror(phase, in(2));
 991 
 992     if (k1 && (k2 || conk2)) {
 993       Node* lhs = k1;
 994       Node* rhs = (k2 != NULL) ? k2 : conk2;
 995 #if INCLUDE_SHENANDOAHGC
 996       PhaseIterGVN* igvn = phase->is_IterGVN();
 997       if (UseShenandoahGC && igvn != NULL) {
 998         set_req_X(1, lhs, igvn);
 999         set_req_X(2, rhs, igvn);
1000       } else
1001 #endif
1002       {
1003         set_req(1, lhs);
1004         set_req(2, rhs);
1005       }
1006       return this;
1007     }
1008   }
1009 
1010   // Constant pointer on right?
1011   const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
1012   if (t2 == NULL || !t2->klass_is_exact())
1013     return NULL;
1014   // Get the constant klass we are comparing to.
1015   ciKlass* superklass = t2->klass();
1016 
1017   // Now check for LoadKlass on left.
1018   Node* ldk1 = in(1);
1019   if (ldk1->is_DecodeNKlass()) {
1020     ldk1 = ldk1->in(1);
1021     if (ldk1->Opcode() != Op_LoadNKlass )
1022       return NULL;
1023   } else if (ldk1->Opcode() != Op_LoadKlass )
1024     return NULL;
1025   // Take apart the address of the LoadKlass:


< prev index next >