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/connode.hpp"
32 #include "opto/loopnode.hpp"
33 #include "opto/matcher.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( PhaseTransform *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);
832
833 // Known constants can be compared exactly
834 // Null can be distinguished from any NotNull pointers
835 // Unknown inputs makes an unknown result
836 if( r0->singleton() ) {
837 intptr_t bits0 = r0->get_con();
838 if( r1->singleton() )
839 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
840 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
841 } else if( r1->singleton() ) {
842 intptr_t bits1 = r1->get_con();
843 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
844 } else
845 return TypeInt::CC;
846 }
847
848 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
849 // Return the klass node for
850 // LoadP(AddP(foo:Klass, #java_mirror))
851 // or NULL if not matching.
852 if (n->Opcode() != Op_LoadP) return NULL;
853
854 const TypeInstPtr* tp = phase->type(n)->isa_instptr();
855 if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
856
857 Node* adr = n->in(MemNode::Address);
858 intptr_t off = 0;
859 Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
860 if (k == NULL) return NULL;
861 const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
862 if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
863
864 // We've found the klass node of a Java mirror load.
865 return k;
866 }
867
868 static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) {
869 // for ConP(Foo.class) return ConP(Foo.klass)
870 // otherwise return NULL
871 if (!n->is_Con()) return NULL;
872
873 const TypeInstPtr* tp = phase->type(n)->isa_instptr();
900 // Normalize comparisons between Java mirrors into comparisons of the low-
901 // level klass, where a dependent load could be shortened.
902 //
903 // The new pattern has a nice effect of matching the same pattern used in the
904 // fast path of instanceof/checkcast/Class.isInstance(), which allows
905 // redundant exact type check be optimized away by GVN.
906 // For example, in
907 // if (x.getClass() == Foo.class) {
908 // Foo foo = (Foo) x;
909 // // ... use a ...
910 // }
911 // a CmpPNode could be shared between if_acmpne and checkcast
912 {
913 Node* k1 = isa_java_mirror_load(phase, in(1));
914 Node* k2 = isa_java_mirror_load(phase, in(2));
915 Node* conk2 = isa_const_java_mirror(phase, in(2));
916
917 if (k1 && (k2 || conk2)) {
918 Node* lhs = k1;
919 Node* rhs = (k2 != NULL) ? k2 : conk2;
920 this->set_req(1, lhs);
921 this->set_req(2, rhs);
922 return this;
923 }
924 }
925
926 // Constant pointer on right?
927 const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
928 if (t2 == NULL || !t2->klass_is_exact())
929 return NULL;
930 // Get the constant klass we are comparing to.
931 ciKlass* superklass = t2->klass();
932
933 // Now check for LoadKlass on left.
934 Node* ldk1 = in(1);
935 if (ldk1->is_DecodeNKlass()) {
936 ldk1 = ldk1->in(1);
937 if (ldk1->Opcode() != Op_LoadNKlass )
938 return NULL;
939 } else if (ldk1->Opcode() != Op_LoadKlass )
940 return NULL;
941 // 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/connode.hpp"
32 #include "opto/loopnode.hpp"
33 #include "opto/matcher.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 #if INCLUDE_ALL_GCS
40 #include "gc_implementation/shenandoah/c2/shenandoahBarrierSetC2.hpp"
41 #include "gc_implementation/shenandoah/c2/shenandoahSupport.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( PhaseTransform *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);
836
837 // Known constants can be compared exactly
838 // Null can be distinguished from any NotNull pointers
839 // Unknown inputs makes an unknown result
840 if( r0->singleton() ) {
841 intptr_t bits0 = r0->get_con();
842 if( r1->singleton() )
843 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
844 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
845 } else if( r1->singleton() ) {
846 intptr_t bits1 = r1->get_con();
847 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
848 } else
849 return TypeInt::CC;
850 }
851
852 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
853 // Return the klass node for
854 // LoadP(AddP(foo:Klass, #java_mirror))
855 // or NULL if not matching.
856
857 #if INCLUDE_ALL_GCS
858 if (UseShenandoahGC) {
859 n = ShenandoahBarrierSetC2::bsc2()->step_over_gc_barrier(n);
860 }
861 #endif
862
863 if (n->Opcode() != Op_LoadP) return NULL;
864 const TypeInstPtr* tp = phase->type(n)->isa_instptr();
865 if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
866
867 Node* adr = n->in(MemNode::Address);
868 intptr_t off = 0;
869 Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
870 if (k == NULL) return NULL;
871 const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
872 if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
873
874 // We've found the klass node of a Java mirror load.
875 return k;
876 }
877
878 static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) {
879 // for ConP(Foo.class) return ConP(Foo.klass)
880 // otherwise return NULL
881 if (!n->is_Con()) return NULL;
882
883 const TypeInstPtr* tp = phase->type(n)->isa_instptr();
910 // Normalize comparisons between Java mirrors into comparisons of the low-
911 // level klass, where a dependent load could be shortened.
912 //
913 // The new pattern has a nice effect of matching the same pattern used in the
914 // fast path of instanceof/checkcast/Class.isInstance(), which allows
915 // redundant exact type check be optimized away by GVN.
916 // For example, in
917 // if (x.getClass() == Foo.class) {
918 // Foo foo = (Foo) x;
919 // // ... use a ...
920 // }
921 // a CmpPNode could be shared between if_acmpne and checkcast
922 {
923 Node* k1 = isa_java_mirror_load(phase, in(1));
924 Node* k2 = isa_java_mirror_load(phase, in(2));
925 Node* conk2 = isa_const_java_mirror(phase, in(2));
926
927 if (k1 && (k2 || conk2)) {
928 Node* lhs = k1;
929 Node* rhs = (k2 != NULL) ? k2 : conk2;
930 #if INCLUDE_ALL_GCS
931 PhaseIterGVN* igvn = phase->is_IterGVN();
932 if (UseShenandoahGC && igvn != NULL) {
933 set_req_X(1, lhs, igvn);
934 set_req_X(2, rhs, igvn);
935 } else
936 #endif
937 {
938 set_req(1, lhs);
939 set_req(2, rhs);
940 }
941 return this;
942 }
943 }
944
945 // Constant pointer on right?
946 const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
947 if (t2 == NULL || !t2->klass_is_exact())
948 return NULL;
949 // Get the constant klass we are comparing to.
950 ciKlass* superklass = t2->klass();
951
952 // Now check for LoadKlass on left.
953 Node* ldk1 = in(1);
954 if (ldk1->is_DecodeNKlass()) {
955 ldk1 = ldk1->in(1);
956 if (ldk1->Opcode() != Op_LoadNKlass )
957 return NULL;
958 } else if (ldk1->Opcode() != Op_LoadKlass )
959 return NULL;
960 // Take apart the address of the LoadKlass:
|