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