12 * version 2 for more details (a copy is included in the LICENSE file that
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 "compiler/compileLog.hpp"
26 #include "gc/shared/barrierSet.hpp"
27 #include "gc/shared/c2/barrierSetC2.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "opto/addnode.hpp"
30 #include "opto/callnode.hpp"
31 #include "opto/cfgnode.hpp"
32 #include "opto/loopnode.hpp"
33 #include "opto/matcher.hpp"
34 #include "opto/movenode.hpp"
35 #include "opto/mulnode.hpp"
36 #include "opto/opaquenode.hpp"
37 #include "opto/opcodes.hpp"
38 #include "opto/phaseX.hpp"
39 #include "opto/subnode.hpp"
40 #include "runtime/sharedRuntime.hpp"
41 #include "utilities/reverse_bits.hpp"
42
43 // Portions of code courtesy of Clifford Click
44
45 // Optimization - Graph Style
46
47 #include "math.h"
48
49 //=============================================================================
50 //------------------------------Identity---------------------------------------
51 // If right input is a constant 0, return the left input.
892 switch (in(1)->Opcode()) {
893 case Op_CmpU3: // Collapse a CmpU3/CmpI into a CmpU
894 return new CmpUNode(in(1)->in(1),in(1)->in(2));
895 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
896 return new CmpLNode(in(1)->in(1),in(1)->in(2));
897 case Op_CmpUL3: // Collapse a CmpUL3/CmpI into a CmpUL
898 return new CmpULNode(in(1)->in(1),in(1)->in(2));
899 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
900 return new CmpFNode(in(1)->in(1),in(1)->in(2));
901 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
902 return new CmpDNode(in(1)->in(1),in(1)->in(2));
903 //case Op_SubI:
904 // If (x - y) cannot overflow, then ((x - y) <?> 0)
905 // can be turned into (x <?> y).
906 // This is handled (with more general cases) by Ideal_sub_algebra.
907 }
908 }
909 return nullptr; // No change
910 }
911
912 Node *CmpLNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
913 const TypeLong *t2 = phase->type(in(2))->isa_long();
914 if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
915 const jlong con = t2->get_con();
916 if (con >= min_jint && con <= max_jint) {
917 return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
918 }
919 }
920 return nullptr;
921 }
922
923 //=============================================================================
924 // Simplify a CmpL (compare 2 longs ) node, based on local information.
925 // If both inputs are constants, compare them.
926 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
927 const TypeLong *r0 = t1->is_long(); // Handy access
928 const TypeLong *r1 = t2->is_long();
929
930 if( r0->_hi < r1->_lo ) // Range is always low?
931 return TypeInt::CC_LT;
932 else if( r0->_lo > r1->_hi ) // Range is always high?
933 return TypeInt::CC_GT;
934
935 else if( r0->is_con() && r1->is_con() ) { // comparing constants?
936 assert(r0->get_con() == r1->get_con(), "must be equal");
937 return TypeInt::CC_EQ; // Equal results.
938 } else if( r0->_hi == r1->_lo ) // Range is never high?
939 return TypeInt::CC_LE;
940 else if( r0->_lo == r1->_hi ) // Range is never low?
941 return TypeInt::CC_GE;
942 return TypeInt::CC; // else use worst case results
1028 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, nullptr)) {
1029 return TypeInt::CC_GT; // different pointers
1030 }
1031 }
1032 bool xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
1033 bool xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
1034 bool unrelated_classes = false;
1035
1036 if ((p0 && p0->is_same_java_type_as(p1)) ||
1037 (k0 && k0->is_same_java_type_as(k1))) {
1038 } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
1039 (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1040 unrelated_classes = true;
1041 } else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1042 (k0 && !k1->maybe_java_subtype_of(k0))) {
1043 unrelated_classes = xklass1;
1044 } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1045 (k0 && !k0->maybe_java_subtype_of(k1))) {
1046 unrelated_classes = xklass0;
1047 }
1048
1049 if (unrelated_classes) {
1050 // The oops classes are known to be unrelated. If the joined PTRs of
1051 // two oops is not Null and not Bottom, then we are sure that one
1052 // of the two oops is non-null, and the comparison will always fail.
1053 TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1054 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1055 return TypeInt::CC_GT;
1056 }
1057 }
1058 }
1059
1060 // Known constants can be compared exactly
1061 // Null can be distinguished from any NotNull pointers
1062 // Unknown inputs makes an unknown result
1063 if( r0->singleton() ) {
1064 intptr_t bits0 = r0->get_con();
1065 if( r1->singleton() )
1066 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1067 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1068 } else if( r1->singleton() ) {
1113 if (!mirror_type) return nullptr;
1114
1115 // x.getClass() == int.class can never be true (for all primitive types)
1116 // Return a ConP(null) node for this case.
1117 if (mirror_type->is_classless()) {
1118 return phase->makecon(TypePtr::NULL_PTR);
1119 }
1120
1121 // return the ConP(Foo.klass)
1122 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1123 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1124 }
1125
1126 //------------------------------Ideal------------------------------------------
1127 // Normalize comparisons between Java mirror loads to compare the klass instead.
1128 //
1129 // Also check for the case of comparing an unknown klass loaded from the primary
1130 // super-type array vs a known klass with no subtypes. This amounts to
1131 // checking to see an unknown klass subtypes a known klass with no subtypes;
1132 // this only happens on an exact match. We can shorten this test by 1 load.
1133 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
1134 // Normalize comparisons between Java mirrors into comparisons of the low-
1135 // level klass, where a dependent load could be shortened.
1136 //
1137 // The new pattern has a nice effect of matching the same pattern used in the
1138 // fast path of instanceof/checkcast/Class.isInstance(), which allows
1139 // redundant exact type check be optimized away by GVN.
1140 // For example, in
1141 // if (x.getClass() == Foo.class) {
1142 // Foo foo = (Foo) x;
1143 // // ... use a ...
1144 // }
1145 // a CmpPNode could be shared between if_acmpne and checkcast
1146 {
1147 Node* k1 = isa_java_mirror_load(phase, in(1));
1148 Node* k2 = isa_java_mirror_load(phase, in(2));
1149 Node* conk2 = isa_const_java_mirror(phase, in(2));
1150
1151 if (k1 && (k2 || conk2)) {
1152 Node* lhs = k1;
1153 Node* rhs = (k2 != nullptr) ? k2 : conk2;
1185 superklass->is_abstract()) {
1186 // Make it come out always false:
1187 this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1188 return this;
1189 }
1190 }
1191
1192 // Check for a LoadKlass from primary supertype array.
1193 // Any nested loadklass from loadklass+con must be from the p.s. array.
1194 if (ldk2->is_DecodeNKlass()) {
1195 // Keep ldk2 as DecodeN since it could be used in CmpP below.
1196 if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1197 return nullptr;
1198 } else if (ldk2->Opcode() != Op_LoadKlass)
1199 return nullptr;
1200
1201 // Verify that we understand the situation
1202 if (con2 != (intptr_t) superklass->super_check_offset())
1203 return nullptr; // Might be element-klass loading from array klass
1204
1205 // If 'superklass' has no subklasses and is not an interface, then we are
1206 // assured that the only input which will pass the type check is
1207 // 'superklass' itself.
1208 //
1209 // We could be more liberal here, and allow the optimization on interfaces
1210 // which have a single implementor. This would require us to increase the
1211 // expressiveness of the add_dependency() mechanism.
1212 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
1213
1214 // Object arrays must have their base element have no subtypes
1215 while (superklass->is_obj_array_klass()) {
1216 ciType* elem = superklass->as_obj_array_klass()->element_type();
1217 superklass = elem->as_klass();
1218 }
1219 if (superklass->is_instance_klass()) {
1220 ciInstanceKlass* ik = superklass->as_instance_klass();
1221 if (ik->has_subklass() || ik->is_interface()) return nullptr;
1222 // Add a dependency if there is a chance that a subclass will be added later.
1223 if (!ik->is_final()) {
1224 phase->C->dependencies()->assert_leaf_type(ik);
1328 if( t2_value_as_double == (double)t2_value_as_float ) {
1329 // Test value can be represented as a float
1330 // Eliminate the conversion to double and create new comparison
1331 Node *new_in1 = in(idx_f2d)->in(1);
1332 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1333 if( idx_f2d != 1 ) { // Must flip args to match original order
1334 Node *tmp = new_in1;
1335 new_in1 = new_in2;
1336 new_in2 = tmp;
1337 }
1338 CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1339 ? new CmpF3Node( new_in1, new_in2 )
1340 : new CmpFNode ( new_in1, new_in2 ) ;
1341 return new_cmp; // Changed to CmpFNode
1342 }
1343 // Testing value required the precision of a double
1344 }
1345 return nullptr; // No change
1346 }
1347
1348
1349 //=============================================================================
1350 //------------------------------cc2logical-------------------------------------
1351 // Convert a condition code type to a logical type
1352 const Type *BoolTest::cc2logical( const Type *CC ) const {
1353 if( CC == Type::TOP ) return Type::TOP;
1354 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
1355 const TypeInt *ti = CC->is_int();
1356 if( ti->is_con() ) { // Only 1 kind of condition codes set?
1357 // Match low order 2 bits
1358 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1359 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
1360 return TypeInt::make(tmp); // Boolean result
1361 }
1362
1363 if( CC == TypeInt::CC_GE ) {
1364 if( _test == ge ) return TypeInt::ONE;
1365 if( _test == lt ) return TypeInt::ZERO;
1366 }
1367 if( CC == TypeInt::CC_LE ) {
|
12 * version 2 for more details (a copy is included in the LICENSE file that
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 "compiler/compileLog.hpp"
26 #include "gc/shared/barrierSet.hpp"
27 #include "gc/shared/c2/barrierSetC2.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "opto/addnode.hpp"
30 #include "opto/callnode.hpp"
31 #include "opto/cfgnode.hpp"
32 #include "opto/inlinetypenode.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.
893 switch (in(1)->Opcode()) {
894 case Op_CmpU3: // Collapse a CmpU3/CmpI into a CmpU
895 return new CmpUNode(in(1)->in(1),in(1)->in(2));
896 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
897 return new CmpLNode(in(1)->in(1),in(1)->in(2));
898 case Op_CmpUL3: // Collapse a CmpUL3/CmpI into a CmpUL
899 return new CmpULNode(in(1)->in(1),in(1)->in(2));
900 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
901 return new CmpFNode(in(1)->in(1),in(1)->in(2));
902 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
903 return new CmpDNode(in(1)->in(1),in(1)->in(2));
904 //case Op_SubI:
905 // If (x - y) cannot overflow, then ((x - y) <?> 0)
906 // can be turned into (x <?> y).
907 // This is handled (with more general cases) by Ideal_sub_algebra.
908 }
909 }
910 return nullptr; // No change
911 }
912
913 //------------------------------Ideal------------------------------------------
914 Node* CmpLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
915 Node* a = nullptr;
916 Node* b = nullptr;
917 if (is_double_null_check(phase, a, b) && (phase->type(a)->is_zero_type() || phase->type(b)->is_zero_type())) {
918 // Degraded to a simple null check, use old acmp
919 return new CmpPNode(a, b);
920 }
921 const TypeLong *t2 = phase->type(in(2))->isa_long();
922 if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
923 const jlong con = t2->get_con();
924 if (con >= min_jint && con <= max_jint) {
925 return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
926 }
927 }
928 return nullptr;
929 }
930
931 // Match double null check emitted by Compile::optimize_acmp()
932 bool CmpLNode::is_double_null_check(PhaseGVN* phase, Node*& a, Node*& b) const {
933 if (in(1)->Opcode() == Op_OrL &&
934 in(1)->in(1)->Opcode() == Op_CastP2X &&
935 in(1)->in(2)->Opcode() == Op_CastP2X &&
936 in(2)->bottom_type()->is_zero_type()) {
937 assert(EnableValhalla, "unexpected double null check");
938 a = in(1)->in(1)->in(1);
939 b = in(1)->in(2)->in(1);
940 return true;
941 }
942 return false;
943 }
944
945 //------------------------------Value------------------------------------------
946 const Type* CmpLNode::Value(PhaseGVN* phase) const {
947 Node* a = nullptr;
948 Node* b = nullptr;
949 if (is_double_null_check(phase, a, b) && (!phase->type(a)->maybe_null() || !phase->type(b)->maybe_null())) {
950 // One operand is never nullptr, emit constant false
951 return TypeInt::CC_GT;
952 }
953 return SubNode::Value(phase);
954 }
955
956 //=============================================================================
957 // Simplify a CmpL (compare 2 longs ) node, based on local information.
958 // If both inputs are constants, compare them.
959 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
960 const TypeLong *r0 = t1->is_long(); // Handy access
961 const TypeLong *r1 = t2->is_long();
962
963 if( r0->_hi < r1->_lo ) // Range is always low?
964 return TypeInt::CC_LT;
965 else if( r0->_lo > r1->_hi ) // Range is always high?
966 return TypeInt::CC_GT;
967
968 else if( r0->is_con() && r1->is_con() ) { // comparing constants?
969 assert(r0->get_con() == r1->get_con(), "must be equal");
970 return TypeInt::CC_EQ; // Equal results.
971 } else if( r0->_hi == r1->_lo ) // Range is never high?
972 return TypeInt::CC_LE;
973 else if( r0->_lo == r1->_hi ) // Range is never low?
974 return TypeInt::CC_GE;
975 return TypeInt::CC; // else use worst case results
1061 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, nullptr)) {
1062 return TypeInt::CC_GT; // different pointers
1063 }
1064 }
1065 bool xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
1066 bool xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
1067 bool unrelated_classes = false;
1068
1069 if ((p0 && p0->is_same_java_type_as(p1)) ||
1070 (k0 && k0->is_same_java_type_as(k1))) {
1071 } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
1072 (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1073 unrelated_classes = true;
1074 } else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1075 (k0 && !k1->maybe_java_subtype_of(k0))) {
1076 unrelated_classes = xklass1;
1077 } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1078 (k0 && !k0->maybe_java_subtype_of(k1))) {
1079 unrelated_classes = xklass0;
1080 }
1081 if (!unrelated_classes) {
1082 // Handle inline type arrays
1083 if ((r0->flat_in_array() && r1->not_flat_in_array()) ||
1084 (r1->flat_in_array() && r0->not_flat_in_array())) {
1085 // One type is in flat arrays but the other type is not. Must be unrelated.
1086 unrelated_classes = true;
1087 } else if ((r0->is_not_flat() && r1->is_flat()) ||
1088 (r1->is_not_flat() && r0->is_flat())) {
1089 // One type is a non-flat array and the other type is a flat array. Must be unrelated.
1090 unrelated_classes = true;
1091 } else if ((r0->is_not_null_free() && r1->is_null_free()) ||
1092 (r1->is_not_null_free() && r0->is_null_free())) {
1093 // One type is a nullable array and the other type is a null-free array. Must be unrelated.
1094 unrelated_classes = true;
1095 }
1096 }
1097 if (unrelated_classes) {
1098 // The oops classes are known to be unrelated. If the joined PTRs of
1099 // two oops is not Null and not Bottom, then we are sure that one
1100 // of the two oops is non-null, and the comparison will always fail.
1101 TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1102 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1103 return TypeInt::CC_GT;
1104 }
1105 }
1106 }
1107
1108 // Known constants can be compared exactly
1109 // Null can be distinguished from any NotNull pointers
1110 // Unknown inputs makes an unknown result
1111 if( r0->singleton() ) {
1112 intptr_t bits0 = r0->get_con();
1113 if( r1->singleton() )
1114 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1115 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1116 } else if( r1->singleton() ) {
1161 if (!mirror_type) return nullptr;
1162
1163 // x.getClass() == int.class can never be true (for all primitive types)
1164 // Return a ConP(null) node for this case.
1165 if (mirror_type->is_classless()) {
1166 return phase->makecon(TypePtr::NULL_PTR);
1167 }
1168
1169 // return the ConP(Foo.klass)
1170 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1171 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1172 }
1173
1174 //------------------------------Ideal------------------------------------------
1175 // Normalize comparisons between Java mirror loads to compare the klass instead.
1176 //
1177 // Also check for the case of comparing an unknown klass loaded from the primary
1178 // super-type array vs a known klass with no subtypes. This amounts to
1179 // checking to see an unknown klass subtypes a known klass with no subtypes;
1180 // this only happens on an exact match. We can shorten this test by 1 load.
1181 Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1182 // TODO 8284443 in(1) could be cast?
1183 if (in(1)->is_InlineType() && phase->type(in(2))->is_zero_type()) {
1184 // Null checking a scalarized but nullable inline type. Check the IsInit
1185 // input instead of the oop input to avoid keeping buffer allocations alive.
1186 return new CmpINode(in(1)->as_InlineType()->get_is_init(), phase->intcon(0));
1187 }
1188
1189 // Normalize comparisons between Java mirrors into comparisons of the low-
1190 // level klass, where a dependent load could be shortened.
1191 //
1192 // The new pattern has a nice effect of matching the same pattern used in the
1193 // fast path of instanceof/checkcast/Class.isInstance(), which allows
1194 // redundant exact type check be optimized away by GVN.
1195 // For example, in
1196 // if (x.getClass() == Foo.class) {
1197 // Foo foo = (Foo) x;
1198 // // ... use a ...
1199 // }
1200 // a CmpPNode could be shared between if_acmpne and checkcast
1201 {
1202 Node* k1 = isa_java_mirror_load(phase, in(1));
1203 Node* k2 = isa_java_mirror_load(phase, in(2));
1204 Node* conk2 = isa_const_java_mirror(phase, in(2));
1205
1206 if (k1 && (k2 || conk2)) {
1207 Node* lhs = k1;
1208 Node* rhs = (k2 != nullptr) ? k2 : conk2;
1240 superklass->is_abstract()) {
1241 // Make it come out always false:
1242 this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1243 return this;
1244 }
1245 }
1246
1247 // Check for a LoadKlass from primary supertype array.
1248 // Any nested loadklass from loadklass+con must be from the p.s. array.
1249 if (ldk2->is_DecodeNKlass()) {
1250 // Keep ldk2 as DecodeN since it could be used in CmpP below.
1251 if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1252 return nullptr;
1253 } else if (ldk2->Opcode() != Op_LoadKlass)
1254 return nullptr;
1255
1256 // Verify that we understand the situation
1257 if (con2 != (intptr_t) superklass->super_check_offset())
1258 return nullptr; // Might be element-klass loading from array klass
1259
1260 // Do not fold the subtype check to an array klass pointer comparison for null-able inline type arrays
1261 // because null-free [LMyValue <: null-able [LMyValue but the klasses are different. Perform a full test.
1262 if (superklass->is_obj_array_klass() && !superklass->as_array_klass()->is_elem_null_free() &&
1263 superklass->as_array_klass()->element_klass()->is_inlinetype()) {
1264 return nullptr;
1265 }
1266
1267 // If 'superklass' has no subklasses and is not an interface, then we are
1268 // assured that the only input which will pass the type check is
1269 // 'superklass' itself.
1270 //
1271 // We could be more liberal here, and allow the optimization on interfaces
1272 // which have a single implementor. This would require us to increase the
1273 // expressiveness of the add_dependency() mechanism.
1274 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
1275
1276 // Object arrays must have their base element have no subtypes
1277 while (superklass->is_obj_array_klass()) {
1278 ciType* elem = superklass->as_obj_array_klass()->element_type();
1279 superklass = elem->as_klass();
1280 }
1281 if (superklass->is_instance_klass()) {
1282 ciInstanceKlass* ik = superklass->as_instance_klass();
1283 if (ik->has_subklass() || ik->is_interface()) return nullptr;
1284 // Add a dependency if there is a chance that a subclass will be added later.
1285 if (!ik->is_final()) {
1286 phase->C->dependencies()->assert_leaf_type(ik);
1390 if( t2_value_as_double == (double)t2_value_as_float ) {
1391 // Test value can be represented as a float
1392 // Eliminate the conversion to double and create new comparison
1393 Node *new_in1 = in(idx_f2d)->in(1);
1394 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1395 if( idx_f2d != 1 ) { // Must flip args to match original order
1396 Node *tmp = new_in1;
1397 new_in1 = new_in2;
1398 new_in2 = tmp;
1399 }
1400 CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1401 ? new CmpF3Node( new_in1, new_in2 )
1402 : new CmpFNode ( new_in1, new_in2 ) ;
1403 return new_cmp; // Changed to CmpFNode
1404 }
1405 // Testing value required the precision of a double
1406 }
1407 return nullptr; // No change
1408 }
1409
1410 //=============================================================================
1411 //------------------------------Value------------------------------------------
1412 const Type* FlatArrayCheckNode::Value(PhaseGVN* phase) const {
1413 bool all_not_flat = true;
1414 for (uint i = ArrayOrKlass; i < req(); ++i) {
1415 const Type* t = phase->type(in(i));
1416 if (t == Type::TOP) {
1417 return Type::TOP;
1418 }
1419 if (t->is_ptr()->is_flat()) {
1420 // One of the input arrays is flat, check always passes
1421 return TypeInt::CC_EQ;
1422 } else if (!t->is_ptr()->is_not_flat()) {
1423 // One of the input arrays might be flat
1424 all_not_flat = false;
1425 }
1426 }
1427 if (all_not_flat) {
1428 // None of the input arrays can be flat, check always fails
1429 return TypeInt::CC_GT;
1430 }
1431 return TypeInt::CC;
1432 }
1433
1434 //------------------------------Ideal------------------------------------------
1435 Node* FlatArrayCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1436 bool changed = false;
1437 // Remove inputs that are known to be non-flat
1438 for (uint i = ArrayOrKlass; i < req(); ++i) {
1439 const Type* t = phase->type(in(i));
1440 if (t->isa_ptr() && t->is_ptr()->is_not_flat()) {
1441 del_req(i--);
1442 changed = true;
1443 }
1444 }
1445 return changed ? this : nullptr;
1446 }
1447
1448 //=============================================================================
1449 //------------------------------cc2logical-------------------------------------
1450 // Convert a condition code type to a logical type
1451 const Type *BoolTest::cc2logical( const Type *CC ) const {
1452 if( CC == Type::TOP ) return Type::TOP;
1453 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
1454 const TypeInt *ti = CC->is_int();
1455 if( ti->is_con() ) { // Only 1 kind of condition codes set?
1456 // Match low order 2 bits
1457 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1458 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
1459 return TypeInt::make(tmp); // Boolean result
1460 }
1461
1462 if( CC == TypeInt::CC_GE ) {
1463 if( _test == ge ) return TypeInt::ONE;
1464 if( _test == lt ) return TypeInt::ZERO;
1465 }
1466 if( CC == TypeInt::CC_LE ) {
|