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