13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 "gc/shared/barrierSet.hpp"
28 #include "gc/shared/c2/barrierSetC2.hpp"
29 #include "memory/allocation.inline.hpp"
30 #include "opto/addnode.hpp"
31 #include "opto/callnode.hpp"
32 #include "opto/cfgnode.hpp"
33 #include "opto/loopnode.hpp"
34 #include "opto/matcher.hpp"
35 #include "opto/movenode.hpp"
36 #include "opto/mulnode.hpp"
37 #include "opto/opaquenode.hpp"
38 #include "opto/opcodes.hpp"
39 #include "opto/phaseX.hpp"
40 #include "opto/subnode.hpp"
41 #include "runtime/sharedRuntime.hpp"
42 #include "utilities/reverse_bits.hpp"
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.
867 switch (in(1)->Opcode()) {
868 case Op_CmpU3: // Collapse a CmpU3/CmpI into a CmpU
869 return new CmpUNode(in(1)->in(1),in(1)->in(2));
870 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
871 return new CmpLNode(in(1)->in(1),in(1)->in(2));
872 case Op_CmpUL3: // Collapse a CmpUL3/CmpI into a CmpUL
873 return new CmpULNode(in(1)->in(1),in(1)->in(2));
874 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
875 return new CmpFNode(in(1)->in(1),in(1)->in(2));
876 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
877 return new CmpDNode(in(1)->in(1),in(1)->in(2));
878 //case Op_SubI:
879 // If (x - y) cannot overflow, then ((x - y) <?> 0)
880 // can be turned into (x <?> y).
881 // This is handled (with more general cases) by Ideal_sub_algebra.
882 }
883 }
884 return nullptr; // No change
885 }
886
887 Node *CmpLNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
888 const TypeLong *t2 = phase->type(in(2))->isa_long();
889 if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
890 const jlong con = t2->get_con();
891 if (con >= min_jint && con <= max_jint) {
892 return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
893 }
894 }
895 return nullptr;
896 }
897
898 //=============================================================================
899 // Simplify a CmpL (compare 2 longs ) node, based on local information.
900 // If both inputs are constants, compare them.
901 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
902 const TypeLong *r0 = t1->is_long(); // Handy access
903 const TypeLong *r1 = t2->is_long();
904
905 if( r0->_hi < r1->_lo ) // Range is always low?
906 return TypeInt::CC_LT;
907 else if( r0->_lo > r1->_hi ) // Range is always high?
908 return TypeInt::CC_GT;
909
910 else if( r0->is_con() && r1->is_con() ) { // comparing constants?
911 assert(r0->get_con() == r1->get_con(), "must be equal");
912 return TypeInt::CC_EQ; // Equal results.
913 } else if( r0->_hi == r1->_lo ) // Range is never high?
914 return TypeInt::CC_LE;
915 else if( r0->_lo == r1->_hi ) // Range is never low?
916 return TypeInt::CC_GE;
917 return TypeInt::CC; // else use worst case results
1003 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, nullptr)) {
1004 return TypeInt::CC_GT; // different pointers
1005 }
1006 }
1007 bool xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
1008 bool xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
1009 bool unrelated_classes = false;
1010
1011 if ((p0 && p0->is_same_java_type_as(p1)) ||
1012 (k0 && k0->is_same_java_type_as(k1))) {
1013 } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
1014 (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1015 unrelated_classes = true;
1016 } else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1017 (k0 && !k1->maybe_java_subtype_of(k0))) {
1018 unrelated_classes = xklass1;
1019 } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1020 (k0 && !k0->maybe_java_subtype_of(k1))) {
1021 unrelated_classes = xklass0;
1022 }
1023
1024 if (unrelated_classes) {
1025 // The oops classes are known to be unrelated. If the joined PTRs of
1026 // two oops is not Null and not Bottom, then we are sure that one
1027 // of the two oops is non-null, and the comparison will always fail.
1028 TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1029 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1030 return TypeInt::CC_GT;
1031 }
1032 }
1033 }
1034
1035 // Known constants can be compared exactly
1036 // Null can be distinguished from any NotNull pointers
1037 // Unknown inputs makes an unknown result
1038 if( r0->singleton() ) {
1039 intptr_t bits0 = r0->get_con();
1040 if( r1->singleton() )
1041 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1042 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1043 } else if( r1->singleton() ) {
1078 // for ConP(Foo.class) return ConP(Foo.klass)
1079 // otherwise return null
1080 if (!n->is_Con()) return nullptr;
1081
1082 const TypeInstPtr* tp = phase->type(n)->isa_instptr();
1083 if (!tp) return nullptr;
1084
1085 ciType* mirror_type = tp->java_mirror_type();
1086 // TypeInstPtr::java_mirror_type() returns non-null for compile-
1087 // time Class constants only.
1088 if (!mirror_type) return nullptr;
1089
1090 // x.getClass() == int.class can never be true (for all primitive types)
1091 // Return a ConP(null) node for this case.
1092 if (mirror_type->is_classless()) {
1093 return phase->makecon(TypePtr::NULL_PTR);
1094 }
1095
1096 // return the ConP(Foo.klass)
1097 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1098 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1099 }
1100
1101 //------------------------------Ideal------------------------------------------
1102 // Normalize comparisons between Java mirror loads to compare the klass instead.
1103 //
1104 // Also check for the case of comparing an unknown klass loaded from the primary
1105 // super-type array vs a known klass with no subtypes. This amounts to
1106 // checking to see an unknown klass subtypes a known klass with no subtypes;
1107 // this only happens on an exact match. We can shorten this test by 1 load.
1108 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
1109 // Normalize comparisons between Java mirrors into comparisons of the low-
1110 // level klass, where a dependent load could be shortened.
1111 //
1112 // The new pattern has a nice effect of matching the same pattern used in the
1113 // fast path of instanceof/checkcast/Class.isInstance(), which allows
1114 // redundant exact type check be optimized away by GVN.
1115 // For example, in
1116 // if (x.getClass() == Foo.class) {
1117 // Foo foo = (Foo) x;
1118 // // ... use a ...
1119 // }
1120 // a CmpPNode could be shared between if_acmpne and checkcast
1121 {
1122 Node* k1 = isa_java_mirror_load(phase, in(1));
1123 Node* k2 = isa_java_mirror_load(phase, in(2));
1124 Node* conk2 = isa_const_java_mirror(phase, in(2));
1125
1126 if (k1 && (k2 || conk2)) {
1127 Node* lhs = k1;
1128 Node* rhs = (k2 != nullptr) ? k2 : conk2;
1160 superklass->is_abstract()) {
1161 // Make it come out always false:
1162 this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1163 return this;
1164 }
1165 }
1166
1167 // Check for a LoadKlass from primary supertype array.
1168 // Any nested loadklass from loadklass+con must be from the p.s. array.
1169 if (ldk2->is_DecodeNKlass()) {
1170 // Keep ldk2 as DecodeN since it could be used in CmpP below.
1171 if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1172 return nullptr;
1173 } else if (ldk2->Opcode() != Op_LoadKlass)
1174 return nullptr;
1175
1176 // Verify that we understand the situation
1177 if (con2 != (intptr_t) superklass->super_check_offset())
1178 return nullptr; // Might be element-klass loading from array klass
1179
1180 // If 'superklass' has no subklasses and is not an interface, then we are
1181 // assured that the only input which will pass the type check is
1182 // 'superklass' itself.
1183 //
1184 // We could be more liberal here, and allow the optimization on interfaces
1185 // which have a single implementor. This would require us to increase the
1186 // expressiveness of the add_dependency() mechanism.
1187 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
1188
1189 // Object arrays must have their base element have no subtypes
1190 while (superklass->is_obj_array_klass()) {
1191 ciType* elem = superklass->as_obj_array_klass()->element_type();
1192 superklass = elem->as_klass();
1193 }
1194 if (superklass->is_instance_klass()) {
1195 ciInstanceKlass* ik = superklass->as_instance_klass();
1196 if (ik->has_subklass() || ik->is_interface()) return nullptr;
1197 // Add a dependency if there is a chance that a subclass will be added later.
1198 if (!ik->is_final()) {
1199 phase->C->dependencies()->assert_leaf_type(ik);
1303 if( t2_value_as_double == (double)t2_value_as_float ) {
1304 // Test value can be represented as a float
1305 // Eliminate the conversion to double and create new comparison
1306 Node *new_in1 = in(idx_f2d)->in(1);
1307 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1308 if( idx_f2d != 1 ) { // Must flip args to match original order
1309 Node *tmp = new_in1;
1310 new_in1 = new_in2;
1311 new_in2 = tmp;
1312 }
1313 CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1314 ? new CmpF3Node( new_in1, new_in2 )
1315 : new CmpFNode ( new_in1, new_in2 ) ;
1316 return new_cmp; // Changed to CmpFNode
1317 }
1318 // Testing value required the precision of a double
1319 }
1320 return nullptr; // No change
1321 }
1322
1323
1324 //=============================================================================
1325 //------------------------------cc2logical-------------------------------------
1326 // Convert a condition code type to a logical type
1327 const Type *BoolTest::cc2logical( const Type *CC ) const {
1328 if( CC == Type::TOP ) return Type::TOP;
1329 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
1330 const TypeInt *ti = CC->is_int();
1331 if( ti->is_con() ) { // Only 1 kind of condition codes set?
1332 // Match low order 2 bits
1333 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1334 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
1335 return TypeInt::make(tmp); // Boolean result
1336 }
1337
1338 if( CC == TypeInt::CC_GE ) {
1339 if( _test == ge ) return TypeInt::ONE;
1340 if( _test == lt ) return TypeInt::ZERO;
1341 }
1342 if( CC == TypeInt::CC_LE ) {
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 "gc/shared/barrierSet.hpp"
28 #include "gc/shared/c2/barrierSetC2.hpp"
29 #include "memory/allocation.inline.hpp"
30 #include "opto/addnode.hpp"
31 #include "opto/callnode.hpp"
32 #include "opto/cfgnode.hpp"
33 #include "opto/inlinetypenode.hpp"
34 #include "opto/loopnode.hpp"
35 #include "opto/matcher.hpp"
36 #include "opto/movenode.hpp"
37 #include "opto/mulnode.hpp"
38 #include "opto/opaquenode.hpp"
39 #include "opto/opcodes.hpp"
40 #include "opto/phaseX.hpp"
41 #include "opto/subnode.hpp"
42 #include "runtime/sharedRuntime.hpp"
43 #include "utilities/reverse_bits.hpp"
44
45 // Portions of code courtesy of Clifford Click
46
47 // Optimization - Graph Style
48
49 #include "math.h"
50
51 //=============================================================================
52 //------------------------------Identity---------------------------------------
53 // If right input is a constant 0, return the left input.
868 switch (in(1)->Opcode()) {
869 case Op_CmpU3: // Collapse a CmpU3/CmpI into a CmpU
870 return new CmpUNode(in(1)->in(1),in(1)->in(2));
871 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
872 return new CmpLNode(in(1)->in(1),in(1)->in(2));
873 case Op_CmpUL3: // Collapse a CmpUL3/CmpI into a CmpUL
874 return new CmpULNode(in(1)->in(1),in(1)->in(2));
875 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
876 return new CmpFNode(in(1)->in(1),in(1)->in(2));
877 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
878 return new CmpDNode(in(1)->in(1),in(1)->in(2));
879 //case Op_SubI:
880 // If (x - y) cannot overflow, then ((x - y) <?> 0)
881 // can be turned into (x <?> y).
882 // This is handled (with more general cases) by Ideal_sub_algebra.
883 }
884 }
885 return nullptr; // No change
886 }
887
888 //------------------------------Ideal------------------------------------------
889 Node* CmpLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
890 Node* a = nullptr;
891 Node* b = nullptr;
892 if (is_double_null_check(phase, a, b) && (phase->type(a)->is_zero_type() || phase->type(b)->is_zero_type())) {
893 // Degraded to a simple null check, use old acmp
894 return new CmpPNode(a, b);
895 }
896 const TypeLong *t2 = phase->type(in(2))->isa_long();
897 if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
898 const jlong con = t2->get_con();
899 if (con >= min_jint && con <= max_jint) {
900 return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
901 }
902 }
903 return nullptr;
904 }
905
906 // Match double null check emitted by Compile::optimize_acmp()
907 bool CmpLNode::is_double_null_check(PhaseGVN* phase, Node*& a, Node*& b) const {
908 if (in(1)->Opcode() == Op_OrL &&
909 in(1)->in(1)->Opcode() == Op_CastP2X &&
910 in(1)->in(2)->Opcode() == Op_CastP2X &&
911 in(2)->bottom_type()->is_zero_type()) {
912 assert(EnableValhalla, "unexpected double null check");
913 a = in(1)->in(1)->in(1);
914 b = in(1)->in(2)->in(1);
915 return true;
916 }
917 return false;
918 }
919
920 //------------------------------Value------------------------------------------
921 const Type* CmpLNode::Value(PhaseGVN* phase) const {
922 Node* a = nullptr;
923 Node* b = nullptr;
924 if (is_double_null_check(phase, a, b) && (!phase->type(a)->maybe_null() || !phase->type(b)->maybe_null())) {
925 // One operand is never nullptr, emit constant false
926 return TypeInt::CC_GT;
927 }
928 return SubNode::Value(phase);
929 }
930
931 //=============================================================================
932 // Simplify a CmpL (compare 2 longs ) node, based on local information.
933 // If both inputs are constants, compare them.
934 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
935 const TypeLong *r0 = t1->is_long(); // Handy access
936 const TypeLong *r1 = t2->is_long();
937
938 if( r0->_hi < r1->_lo ) // Range is always low?
939 return TypeInt::CC_LT;
940 else if( r0->_lo > r1->_hi ) // Range is always high?
941 return TypeInt::CC_GT;
942
943 else if( r0->is_con() && r1->is_con() ) { // comparing constants?
944 assert(r0->get_con() == r1->get_con(), "must be equal");
945 return TypeInt::CC_EQ; // Equal results.
946 } else if( r0->_hi == r1->_lo ) // Range is never high?
947 return TypeInt::CC_LE;
948 else if( r0->_lo == r1->_hi ) // Range is never low?
949 return TypeInt::CC_GE;
950 return TypeInt::CC; // else use worst case results
1036 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, nullptr)) {
1037 return TypeInt::CC_GT; // different pointers
1038 }
1039 }
1040 bool xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
1041 bool xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
1042 bool unrelated_classes = false;
1043
1044 if ((p0 && p0->is_same_java_type_as(p1)) ||
1045 (k0 && k0->is_same_java_type_as(k1))) {
1046 } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
1047 (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1048 unrelated_classes = true;
1049 } else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1050 (k0 && !k1->maybe_java_subtype_of(k0))) {
1051 unrelated_classes = xklass1;
1052 } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1053 (k0 && !k0->maybe_java_subtype_of(k1))) {
1054 unrelated_classes = xklass0;
1055 }
1056 if (!unrelated_classes) {
1057 // Handle inline type arrays
1058 if ((r0->flat_in_array() && r1->not_flat_in_array()) ||
1059 (r1->flat_in_array() && r0->not_flat_in_array())) {
1060 // One type is in flat arrays but the other type is not. Must be unrelated.
1061 unrelated_classes = true;
1062 } else if ((r0->is_not_flat() && r1->is_flat()) ||
1063 (r1->is_not_flat() && r0->is_flat())) {
1064 // One type is a non-flat array and the other type is a flat array. Must be unrelated.
1065 unrelated_classes = true;
1066 } else if ((r0->is_not_null_free() && r1->is_null_free()) ||
1067 (r1->is_not_null_free() && r0->is_null_free())) {
1068 // One type is a nullable array and the other type is a null-free array. Must be unrelated.
1069 unrelated_classes = true;
1070 }
1071 }
1072 if (unrelated_classes) {
1073 // The oops classes are known to be unrelated. If the joined PTRs of
1074 // two oops is not Null and not Bottom, then we are sure that one
1075 // of the two oops is non-null, and the comparison will always fail.
1076 TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1077 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1078 return TypeInt::CC_GT;
1079 }
1080 }
1081 }
1082
1083 // Known constants can be compared exactly
1084 // Null can be distinguished from any NotNull pointers
1085 // Unknown inputs makes an unknown result
1086 if( r0->singleton() ) {
1087 intptr_t bits0 = r0->get_con();
1088 if( r1->singleton() )
1089 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1090 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1091 } else if( r1->singleton() ) {
1126 // for ConP(Foo.class) return ConP(Foo.klass)
1127 // otherwise return null
1128 if (!n->is_Con()) return nullptr;
1129
1130 const TypeInstPtr* tp = phase->type(n)->isa_instptr();
1131 if (!tp) return nullptr;
1132
1133 ciType* mirror_type = tp->java_mirror_type();
1134 // TypeInstPtr::java_mirror_type() returns non-null for compile-
1135 // time Class constants only.
1136 if (!mirror_type) return nullptr;
1137
1138 // x.getClass() == int.class can never be true (for all primitive types)
1139 // Return a ConP(null) node for this case.
1140 if (mirror_type->is_classless()) {
1141 return phase->makecon(TypePtr::NULL_PTR);
1142 }
1143
1144 // return the ConP(Foo.klass)
1145 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1146 // TODO 8325106 Handle null free arrays here?
1147 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1148 }
1149
1150 //------------------------------Ideal------------------------------------------
1151 // Normalize comparisons between Java mirror loads to compare the klass instead.
1152 //
1153 // Also check for the case of comparing an unknown klass loaded from the primary
1154 // super-type array vs a known klass with no subtypes. This amounts to
1155 // checking to see an unknown klass subtypes a known klass with no subtypes;
1156 // this only happens on an exact match. We can shorten this test by 1 load.
1157 Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1158 // TODO 8284443 in(1) could be cast?
1159 if (in(1)->is_InlineType() && phase->type(in(2))->is_zero_type()) {
1160 // Null checking a scalarized but nullable inline type. Check the IsInit
1161 // input instead of the oop input to avoid keeping buffer allocations alive.
1162 return new CmpINode(in(1)->as_InlineType()->get_is_init(), phase->intcon(0));
1163 }
1164
1165 // Normalize comparisons between Java mirrors into comparisons of the low-
1166 // level klass, where a dependent load could be shortened.
1167 //
1168 // The new pattern has a nice effect of matching the same pattern used in the
1169 // fast path of instanceof/checkcast/Class.isInstance(), which allows
1170 // redundant exact type check be optimized away by GVN.
1171 // For example, in
1172 // if (x.getClass() == Foo.class) {
1173 // Foo foo = (Foo) x;
1174 // // ... use a ...
1175 // }
1176 // a CmpPNode could be shared between if_acmpne and checkcast
1177 {
1178 Node* k1 = isa_java_mirror_load(phase, in(1));
1179 Node* k2 = isa_java_mirror_load(phase, in(2));
1180 Node* conk2 = isa_const_java_mirror(phase, in(2));
1181
1182 if (k1 && (k2 || conk2)) {
1183 Node* lhs = k1;
1184 Node* rhs = (k2 != nullptr) ? k2 : conk2;
1216 superklass->is_abstract()) {
1217 // Make it come out always false:
1218 this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1219 return this;
1220 }
1221 }
1222
1223 // Check for a LoadKlass from primary supertype array.
1224 // Any nested loadklass from loadklass+con must be from the p.s. array.
1225 if (ldk2->is_DecodeNKlass()) {
1226 // Keep ldk2 as DecodeN since it could be used in CmpP below.
1227 if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1228 return nullptr;
1229 } else if (ldk2->Opcode() != Op_LoadKlass)
1230 return nullptr;
1231
1232 // Verify that we understand the situation
1233 if (con2 != (intptr_t) superklass->super_check_offset())
1234 return nullptr; // Might be element-klass loading from array klass
1235
1236 // TODO 8325106 Fix comment
1237 // Do not fold the subtype check to an array klass pointer comparison for [V? arrays.
1238 // [QMyValue is a subtype of [LMyValue but the klass for [QMyValue is not equal to
1239 // the klass for [LMyValue. Do not bypass the klass load from the primary supertype array.
1240 if (superklass->is_obj_array_klass() && !superklass->as_array_klass()->is_elem_null_free() &&
1241 superklass->as_array_klass()->element_klass()->is_inlinetype()) {
1242 return nullptr;
1243 }
1244
1245 // If 'superklass' has no subklasses and is not an interface, then we are
1246 // assured that the only input which will pass the type check is
1247 // 'superklass' itself.
1248 //
1249 // We could be more liberal here, and allow the optimization on interfaces
1250 // which have a single implementor. This would require us to increase the
1251 // expressiveness of the add_dependency() mechanism.
1252 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
1253
1254 // Object arrays must have their base element have no subtypes
1255 while (superklass->is_obj_array_klass()) {
1256 ciType* elem = superklass->as_obj_array_klass()->element_type();
1257 superklass = elem->as_klass();
1258 }
1259 if (superklass->is_instance_klass()) {
1260 ciInstanceKlass* ik = superklass->as_instance_klass();
1261 if (ik->has_subklass() || ik->is_interface()) return nullptr;
1262 // Add a dependency if there is a chance that a subclass will be added later.
1263 if (!ik->is_final()) {
1264 phase->C->dependencies()->assert_leaf_type(ik);
1368 if( t2_value_as_double == (double)t2_value_as_float ) {
1369 // Test value can be represented as a float
1370 // Eliminate the conversion to double and create new comparison
1371 Node *new_in1 = in(idx_f2d)->in(1);
1372 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1373 if( idx_f2d != 1 ) { // Must flip args to match original order
1374 Node *tmp = new_in1;
1375 new_in1 = new_in2;
1376 new_in2 = tmp;
1377 }
1378 CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1379 ? new CmpF3Node( new_in1, new_in2 )
1380 : new CmpFNode ( new_in1, new_in2 ) ;
1381 return new_cmp; // Changed to CmpFNode
1382 }
1383 // Testing value required the precision of a double
1384 }
1385 return nullptr; // No change
1386 }
1387
1388 //=============================================================================
1389 //------------------------------Value------------------------------------------
1390 const Type* FlatArrayCheckNode::Value(PhaseGVN* phase) const {
1391 bool all_not_flat = true;
1392 for (uint i = ArrayOrKlass; i < req(); ++i) {
1393 const Type* t = phase->type(in(i));
1394 if (t == Type::TOP) {
1395 return Type::TOP;
1396 }
1397 if (t->is_ptr()->is_flat()) {
1398 // One of the input arrays is flat, check always passes
1399 return TypeInt::CC_EQ;
1400 } else if (!t->is_ptr()->is_not_flat()) {
1401 // One of the input arrays might be flat
1402 all_not_flat = false;
1403 }
1404 }
1405 if (all_not_flat) {
1406 // None of the input arrays can be flat, check always fails
1407 return TypeInt::CC_GT;
1408 }
1409 return TypeInt::CC;
1410 }
1411
1412 //------------------------------Ideal------------------------------------------
1413 Node* FlatArrayCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1414 bool changed = false;
1415 // Remove inputs that are known to be non-flat
1416 for (uint i = ArrayOrKlass; i < req(); ++i) {
1417 const Type* t = phase->type(in(i));
1418 if (t->isa_ptr() && t->is_ptr()->is_not_flat()) {
1419 del_req(i--);
1420 changed = true;
1421 }
1422 }
1423 return changed ? this : nullptr;
1424 }
1425
1426 //=============================================================================
1427 //------------------------------cc2logical-------------------------------------
1428 // Convert a condition code type to a logical type
1429 const Type *BoolTest::cc2logical( const Type *CC ) const {
1430 if( CC == Type::TOP ) return Type::TOP;
1431 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
1432 const TypeInt *ti = CC->is_int();
1433 if( ti->is_con() ) { // Only 1 kind of condition codes set?
1434 // Match low order 2 bits
1435 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1436 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
1437 return TypeInt::make(tmp); // Boolean result
1438 }
1439
1440 if( CC == TypeInt::CC_GE ) {
1441 if( _test == ge ) return TypeInt::ONE;
1442 if( _test == lt ) return TypeInt::ZERO;
1443 }
1444 if( CC == TypeInt::CC_LE ) {
|