823 return TypeInt::CC_LT; // smaller 824 } else if (lo0 > hi1) { 825 return TypeInt::CC_GT; // greater 826 } else if (hi0 == lo1 && lo0 == hi1) { 827 return TypeInt::CC_EQ; // Equal results 828 } else if (lo0 >= hi1) { 829 return TypeInt::CC_GE; 830 } else if (hi0 <= lo1) { 831 return TypeInt::CC_LE; 832 } 833 } 834 835 return TypeInt::CC; // else use worst case results 836 } 837 838 //============================================================================= 839 //------------------------------sub-------------------------------------------- 840 // Simplify an CmpP (compare 2 pointers) node, based on local information. 841 // If both inputs are constants, compare them. 842 const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const { 843 if (ACmpOnValues != 3 && 844 (t1->isa_valuetype() || t2->isa_valuetype() || 845 ((t1->is_valuetypeptr() || t2->is_valuetypeptr()) && 846 (!t1->maybe_null() || !t2->maybe_null())))) { 847 // One operand is a value type and one operand is never null, fold to constant false 848 return TypeInt::CC_GT; 849 } 850 851 const TypePtr *r0 = t1->is_ptr(); // Handy access 852 const TypePtr *r1 = t2->is_ptr(); 853 854 // Undefined inputs makes for an undefined result 855 if( TypePtr::above_centerline(r0->_ptr) || 856 TypePtr::above_centerline(r1->_ptr) ) 857 return Type::TOP; 858 859 if (r0 == r1 && r0->singleton()) { 860 // Equal pointer constants (klasses, nulls, etc.) 861 return TypeInt::CC_EQ; 862 } 863 864 // See if it is 2 unrelated classes. 865 const TypeOopPtr* p0 = r0->isa_oopptr(); 866 const TypeOopPtr* p1 = r1->isa_oopptr(); 867 if (p0 && p1) { 868 Node* in1 = in(1)->uncast(); 869 Node* in2 = in(2)->uncast(); 870 AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL); 969 970 // x.getClass() == int.class can never be true (for all primitive types) 971 // Return a ConP(NULL) node for this case. 972 if (mirror_type->is_classless()) { 973 return phase->makecon(TypePtr::NULL_PTR); 974 } 975 976 // return the ConP(Foo.klass) 977 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*"); 978 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass())); 979 } 980 981 //------------------------------Ideal------------------------------------------ 982 // Normalize comparisons between Java mirror loads to compare the klass instead. 983 // 984 // Also check for the case of comparing an unknown klass loaded from the primary 985 // super-type array vs a known klass with no subtypes. This amounts to 986 // checking to see an unknown klass subtypes a known klass with no subtypes; 987 // this only happens on an exact match. We can shorten this test by 1 load. 988 Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) { 989 Node* pert = has_perturbed_operand(); 990 if (pert != NULL) { 991 // Optimize new acmp 992 Node* a = pert->in(AddPNode::Base); // unperturbed a 993 Node* b = in(2); 994 Node* cmp = phase->C->optimize_acmp(phase, a, b); 995 if (cmp != NULL) { 996 return cmp; 997 } 998 } 999 1000 // Normalize comparisons between Java mirrors into comparisons of the low- 1001 // level klass, where a dependent load could be shortened. 1002 // 1003 // The new pattern has a nice effect of matching the same pattern used in the 1004 // fast path of instanceof/checkcast/Class.isInstance(), which allows 1005 // redundant exact type check be optimized away by GVN. 1006 // For example, in 1007 // if (x.getClass() == Foo.class) { 1008 // Foo foo = (Foo) x; 1009 // // ... use a ... 1010 // } 1011 // a CmpPNode could be shared between if_acmpne and checkcast 1012 { 1013 Node* k1 = isa_java_mirror_load(phase, in(1)); 1014 Node* k2 = isa_java_mirror_load(phase, in(2)); 1015 Node* conk2 = isa_const_java_mirror(phase, in(2)); 1016 1017 if (k1 && (k2 || conk2)) { 1018 Node* lhs = k1; 1019 Node* rhs = (k2 != NULL) ? k2 : conk2; 1094 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now. 1095 1096 // Object arrays must have their base element have no subtypes 1097 while (superklass->is_obj_array_klass()) { 1098 ciType* elem = superklass->as_obj_array_klass()->element_type(); 1099 superklass = elem->as_klass(); 1100 } 1101 if (superklass->is_instance_klass()) { 1102 ciInstanceKlass* ik = superklass->as_instance_klass(); 1103 if (ik->has_subklass() || ik->is_interface()) return NULL; 1104 // Add a dependency if there is a chance that a subclass will be added later. 1105 if (!ik->is_final()) { 1106 phase->C->dependencies()->assert_leaf_type(ik); 1107 } 1108 } 1109 1110 // Bypass the dependent load, and compare directly 1111 this->set_req(1,ldk2); 1112 1113 return this; 1114 } 1115 1116 // Checks if one operand is perturbed and returns it 1117 Node* CmpPNode::has_perturbed_operand() const { 1118 // We always perturbe the first operand 1119 AddPNode* addP = in(1)->isa_AddP(); 1120 if (addP != NULL) { 1121 Node* base = addP->in(AddPNode::Base); 1122 if (base->is_top()) { 1123 // RawPtr comparison 1124 return NULL; 1125 } 1126 assert(EnableValhalla && ACmpOnValues == 1, "unexpected perturbed oop"); 1127 return in(1); 1128 } 1129 return NULL; 1130 } 1131 1132 //============================================================================= 1133 //------------------------------sub-------------------------------------------- 1134 // Simplify an CmpN (compare 2 pointers) node, based on local information. 1135 // If both inputs are constants, compare them. 1136 const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const { 1137 const TypePtr *r0 = t1->make_ptr(); // Handy access 1138 const TypePtr *r1 = t2->make_ptr(); 1139 1140 // Undefined inputs makes for an undefined result 1141 if ((r0 == NULL) || (r1 == NULL) || 1142 TypePtr::above_centerline(r0->_ptr) || 1143 TypePtr::above_centerline(r1->_ptr)) { 1144 return Type::TOP; 1145 } 1146 if (r0 == r1 && r0->singleton()) { 1147 // Equal pointer constants (klasses, nulls, etc.) 1148 return TypeInt::CC_EQ; 1149 } | 823 return TypeInt::CC_LT; // smaller 824 } else if (lo0 > hi1) { 825 return TypeInt::CC_GT; // greater 826 } else if (hi0 == lo1 && lo0 == hi1) { 827 return TypeInt::CC_EQ; // Equal results 828 } else if (lo0 >= hi1) { 829 return TypeInt::CC_GE; 830 } else if (hi0 <= lo1) { 831 return TypeInt::CC_LE; 832 } 833 } 834 835 return TypeInt::CC; // else use worst case results 836 } 837 838 //============================================================================= 839 //------------------------------sub-------------------------------------------- 840 // Simplify an CmpP (compare 2 pointers) node, based on local information. 841 // If both inputs are constants, compare them. 842 const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const { 843 const TypePtr *r0 = t1->is_ptr(); // Handy access 844 const TypePtr *r1 = t2->is_ptr(); 845 846 // Undefined inputs makes for an undefined result 847 if( TypePtr::above_centerline(r0->_ptr) || 848 TypePtr::above_centerline(r1->_ptr) ) 849 return Type::TOP; 850 851 if (r0 == r1 && r0->singleton()) { 852 // Equal pointer constants (klasses, nulls, etc.) 853 return TypeInt::CC_EQ; 854 } 855 856 // See if it is 2 unrelated classes. 857 const TypeOopPtr* p0 = r0->isa_oopptr(); 858 const TypeOopPtr* p1 = r1->isa_oopptr(); 859 if (p0 && p1) { 860 Node* in1 = in(1)->uncast(); 861 Node* in2 = in(2)->uncast(); 862 AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL); 961 962 // x.getClass() == int.class can never be true (for all primitive types) 963 // Return a ConP(NULL) node for this case. 964 if (mirror_type->is_classless()) { 965 return phase->makecon(TypePtr::NULL_PTR); 966 } 967 968 // return the ConP(Foo.klass) 969 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*"); 970 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass())); 971 } 972 973 //------------------------------Ideal------------------------------------------ 974 // Normalize comparisons between Java mirror loads to compare the klass instead. 975 // 976 // Also check for the case of comparing an unknown klass loaded from the primary 977 // super-type array vs a known klass with no subtypes. This amounts to 978 // checking to see an unknown klass subtypes a known klass with no subtypes; 979 // this only happens on an exact match. We can shorten this test by 1 load. 980 Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) { 981 // Normalize comparisons between Java mirrors into comparisons of the low- 982 // level klass, where a dependent load could be shortened. 983 // 984 // The new pattern has a nice effect of matching the same pattern used in the 985 // fast path of instanceof/checkcast/Class.isInstance(), which allows 986 // redundant exact type check be optimized away by GVN. 987 // For example, in 988 // if (x.getClass() == Foo.class) { 989 // Foo foo = (Foo) x; 990 // // ... use a ... 991 // } 992 // a CmpPNode could be shared between if_acmpne and checkcast 993 { 994 Node* k1 = isa_java_mirror_load(phase, in(1)); 995 Node* k2 = isa_java_mirror_load(phase, in(2)); 996 Node* conk2 = isa_const_java_mirror(phase, in(2)); 997 998 if (k1 && (k2 || conk2)) { 999 Node* lhs = k1; 1000 Node* rhs = (k2 != NULL) ? k2 : conk2; 1075 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now. 1076 1077 // Object arrays must have their base element have no subtypes 1078 while (superklass->is_obj_array_klass()) { 1079 ciType* elem = superklass->as_obj_array_klass()->element_type(); 1080 superklass = elem->as_klass(); 1081 } 1082 if (superklass->is_instance_klass()) { 1083 ciInstanceKlass* ik = superklass->as_instance_klass(); 1084 if (ik->has_subklass() || ik->is_interface()) return NULL; 1085 // Add a dependency if there is a chance that a subclass will be added later. 1086 if (!ik->is_final()) { 1087 phase->C->dependencies()->assert_leaf_type(ik); 1088 } 1089 } 1090 1091 // Bypass the dependent load, and compare directly 1092 this->set_req(1,ldk2); 1093 1094 return this; 1095 } 1096 1097 //============================================================================= 1098 //------------------------------sub-------------------------------------------- 1099 // Simplify an CmpN (compare 2 pointers) node, based on local information. 1100 // If both inputs are constants, compare them. 1101 const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const { 1102 const TypePtr *r0 = t1->make_ptr(); // Handy access 1103 const TypePtr *r1 = t2->make_ptr(); 1104 1105 // Undefined inputs makes for an undefined result 1106 if ((r0 == NULL) || (r1 == NULL) || 1107 TypePtr::above_centerline(r0->_ptr) || 1108 TypePtr::above_centerline(r1->_ptr)) { 1109 return Type::TOP; 1110 } 1111 if (r0 == r1 && r0->singleton()) { 1112 // Equal pointer constants (klasses, nulls, etc.) 1113 return TypeInt::CC_EQ; 1114 } |