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/moveBits.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.
852 switch (in(1)->Opcode()) {
853 case Op_CmpU3: // Collapse a CmpU3/CmpI into a CmpU
854 return new CmpUNode(in(1)->in(1),in(1)->in(2));
855 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
856 return new CmpLNode(in(1)->in(1),in(1)->in(2));
857 case Op_CmpUL3: // Collapse a CmpUL3/CmpI into a CmpUL
858 return new CmpULNode(in(1)->in(1),in(1)->in(2));
859 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
860 return new CmpFNode(in(1)->in(1),in(1)->in(2));
861 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
862 return new CmpDNode(in(1)->in(1),in(1)->in(2));
863 //case Op_SubI:
864 // If (x - y) cannot overflow, then ((x - y) <?> 0)
865 // can be turned into (x <?> y).
866 // This is handled (with more general cases) by Ideal_sub_algebra.
867 }
868 }
869 return NULL; // No change
870 }
871
872 Node *CmpLNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
873 const TypeLong *t2 = phase->type(in(2))->isa_long();
874 if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
875 const jlong con = t2->get_con();
876 if (con >= min_jint && con <= max_jint) {
877 return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
878 }
879 }
880 return NULL;
881 }
882
883 //=============================================================================
884 // Simplify a CmpL (compare 2 longs ) node, based on local information.
885 // If both inputs are constants, compare them.
886 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
887 const TypeLong *r0 = t1->is_long(); // Handy access
888 const TypeLong *r1 = t2->is_long();
889
890 if( r0->_hi < r1->_lo ) // Range is always low?
891 return TypeInt::CC_LT;
892 else if( r0->_lo > r1->_hi ) // Range is always high?
893 return TypeInt::CC_GT;
894
895 else if( r0->is_con() && r1->is_con() ) { // comparing constants?
896 assert(r0->get_con() == r1->get_con(), "must be equal");
897 return TypeInt::CC_EQ; // Equal results.
898 } else if( r0->_hi == r1->_lo ) // Range is never high?
899 return TypeInt::CC_LE;
900 else if( r0->_lo == r1->_hi ) // Range is never low?
901 return TypeInt::CC_GE;
902 return TypeInt::CC; // else use worst case results
988 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
989 return TypeInt::CC_GT; // different pointers
990 }
991 }
992 bool xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
993 bool xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
994 bool unrelated_classes = false;
995
996 if ((p0 && p0->is_same_java_type_as(p1)) ||
997 (k0 && k0->is_same_java_type_as(k1))) {
998 } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
999 (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1000 unrelated_classes = true;
1001 } else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1002 (k0 && !k1->maybe_java_subtype_of(k0))) {
1003 unrelated_classes = xklass1;
1004 } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1005 (k0 && !k0->maybe_java_subtype_of(k1))) {
1006 unrelated_classes = xklass0;
1007 }
1008
1009 if (unrelated_classes) {
1010 // The oops classes are known to be unrelated. If the joined PTRs of
1011 // two oops is not Null and not Bottom, then we are sure that one
1012 // of the two oops is non-null, and the comparison will always fail.
1013 TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1014 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1015 return TypeInt::CC_GT;
1016 }
1017 }
1018 }
1019
1020 // Known constants can be compared exactly
1021 // Null can be distinguished from any NotNull pointers
1022 // Unknown inputs makes an unknown result
1023 if( r0->singleton() ) {
1024 intptr_t bits0 = r0->get_con();
1025 if( r1->singleton() )
1026 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1027 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1028 } else if( r1->singleton() ) {
1073 if (!mirror_type) return NULL;
1074
1075 // x.getClass() == int.class can never be true (for all primitive types)
1076 // Return a ConP(NULL) node for this case.
1077 if (mirror_type->is_classless()) {
1078 return phase->makecon(TypePtr::NULL_PTR);
1079 }
1080
1081 // return the ConP(Foo.klass)
1082 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1083 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1084 }
1085
1086 //------------------------------Ideal------------------------------------------
1087 // Normalize comparisons between Java mirror loads to compare the klass instead.
1088 //
1089 // Also check for the case of comparing an unknown klass loaded from the primary
1090 // super-type array vs a known klass with no subtypes. This amounts to
1091 // checking to see an unknown klass subtypes a known klass with no subtypes;
1092 // this only happens on an exact match. We can shorten this test by 1 load.
1093 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
1094 // Normalize comparisons between Java mirrors into comparisons of the low-
1095 // level klass, where a dependent load could be shortened.
1096 //
1097 // The new pattern has a nice effect of matching the same pattern used in the
1098 // fast path of instanceof/checkcast/Class.isInstance(), which allows
1099 // redundant exact type check be optimized away by GVN.
1100 // For example, in
1101 // if (x.getClass() == Foo.class) {
1102 // Foo foo = (Foo) x;
1103 // // ... use a ...
1104 // }
1105 // a CmpPNode could be shared between if_acmpne and checkcast
1106 {
1107 Node* k1 = isa_java_mirror_load(phase, in(1));
1108 Node* k2 = isa_java_mirror_load(phase, in(2));
1109 Node* conk2 = isa_const_java_mirror(phase, in(2));
1110
1111 if (k1 && (k2 || conk2)) {
1112 Node* lhs = k1;
1113 Node* rhs = (k2 != NULL) ? k2 : conk2;
1145 superklass->is_abstract()) {
1146 // Make it come out always false:
1147 this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1148 return this;
1149 }
1150 }
1151
1152 // Check for a LoadKlass from primary supertype array.
1153 // Any nested loadklass from loadklass+con must be from the p.s. array.
1154 if (ldk2->is_DecodeNKlass()) {
1155 // Keep ldk2 as DecodeN since it could be used in CmpP below.
1156 if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1157 return NULL;
1158 } else if (ldk2->Opcode() != Op_LoadKlass)
1159 return NULL;
1160
1161 // Verify that we understand the situation
1162 if (con2 != (intptr_t) superklass->super_check_offset())
1163 return NULL; // Might be element-klass loading from array klass
1164
1165 // If 'superklass' has no subklasses and is not an interface, then we are
1166 // assured that the only input which will pass the type check is
1167 // 'superklass' itself.
1168 //
1169 // We could be more liberal here, and allow the optimization on interfaces
1170 // which have a single implementor. This would require us to increase the
1171 // expressiveness of the add_dependency() mechanism.
1172 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
1173
1174 // Object arrays must have their base element have no subtypes
1175 while (superklass->is_obj_array_klass()) {
1176 ciType* elem = superklass->as_obj_array_klass()->element_type();
1177 superklass = elem->as_klass();
1178 }
1179 if (superklass->is_instance_klass()) {
1180 ciInstanceKlass* ik = superklass->as_instance_klass();
1181 if (ik->has_subklass() || ik->is_interface()) return NULL;
1182 // Add a dependency if there is a chance that a subclass will be added later.
1183 if (!ik->is_final()) {
1184 phase->C->dependencies()->assert_leaf_type(ik);
1288 if( t2_value_as_double == (double)t2_value_as_float ) {
1289 // Test value can be represented as a float
1290 // Eliminate the conversion to double and create new comparison
1291 Node *new_in1 = in(idx_f2d)->in(1);
1292 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1293 if( idx_f2d != 1 ) { // Must flip args to match original order
1294 Node *tmp = new_in1;
1295 new_in1 = new_in2;
1296 new_in2 = tmp;
1297 }
1298 CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1299 ? new CmpF3Node( new_in1, new_in2 )
1300 : new CmpFNode ( new_in1, new_in2 ) ;
1301 return new_cmp; // Changed to CmpFNode
1302 }
1303 // Testing value required the precision of a double
1304 }
1305 return NULL; // No change
1306 }
1307
1308
1309 //=============================================================================
1310 //------------------------------cc2logical-------------------------------------
1311 // Convert a condition code type to a logical type
1312 const Type *BoolTest::cc2logical( const Type *CC ) const {
1313 if( CC == Type::TOP ) return Type::TOP;
1314 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
1315 const TypeInt *ti = CC->is_int();
1316 if( ti->is_con() ) { // Only 1 kind of condition codes set?
1317 // Match low order 2 bits
1318 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1319 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
1320 return TypeInt::make(tmp); // Boolean result
1321 }
1322
1323 if( CC == TypeInt::CC_GE ) {
1324 if( _test == ge ) return TypeInt::ONE;
1325 if( _test == lt ) return TypeInt::ZERO;
1326 }
1327 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/moveBits.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.
853 switch (in(1)->Opcode()) {
854 case Op_CmpU3: // Collapse a CmpU3/CmpI into a CmpU
855 return new CmpUNode(in(1)->in(1),in(1)->in(2));
856 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
857 return new CmpLNode(in(1)->in(1),in(1)->in(2));
858 case Op_CmpUL3: // Collapse a CmpUL3/CmpI into a CmpUL
859 return new CmpULNode(in(1)->in(1),in(1)->in(2));
860 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
861 return new CmpFNode(in(1)->in(1),in(1)->in(2));
862 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
863 return new CmpDNode(in(1)->in(1),in(1)->in(2));
864 //case Op_SubI:
865 // If (x - y) cannot overflow, then ((x - y) <?> 0)
866 // can be turned into (x <?> y).
867 // This is handled (with more general cases) by Ideal_sub_algebra.
868 }
869 }
870 return NULL; // No change
871 }
872
873 //------------------------------Ideal------------------------------------------
874 Node* CmpLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
875 Node* a = NULL;
876 Node* b = NULL;
877 if (is_double_null_check(phase, a, b) && (phase->type(a)->is_zero_type() || phase->type(b)->is_zero_type())) {
878 // Degraded to a simple null check, use old acmp
879 return new CmpPNode(a, b);
880 }
881 const TypeLong *t2 = phase->type(in(2))->isa_long();
882 if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
883 const jlong con = t2->get_con();
884 if (con >= min_jint && con <= max_jint) {
885 return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
886 }
887 }
888 return NULL;
889 }
890
891 // Match double null check emitted by Compile::optimize_acmp()
892 bool CmpLNode::is_double_null_check(PhaseGVN* phase, Node*& a, Node*& b) const {
893 if (in(1)->Opcode() == Op_OrL &&
894 in(1)->in(1)->Opcode() == Op_CastP2X &&
895 in(1)->in(2)->Opcode() == Op_CastP2X &&
896 in(2)->bottom_type()->is_zero_type()) {
897 assert(EnableValhalla, "unexpected double null check");
898 a = in(1)->in(1)->in(1);
899 b = in(1)->in(2)->in(1);
900 return true;
901 }
902 return false;
903 }
904
905 //------------------------------Value------------------------------------------
906 const Type* CmpLNode::Value(PhaseGVN* phase) const {
907 Node* a = NULL;
908 Node* b = NULL;
909 if (is_double_null_check(phase, a, b) && (!phase->type(a)->maybe_null() || !phase->type(b)->maybe_null())) {
910 // One operand is never NULL, emit constant false
911 return TypeInt::CC_GT;
912 }
913 return SubNode::Value(phase);
914 }
915
916 //=============================================================================
917 // Simplify a CmpL (compare 2 longs ) node, based on local information.
918 // If both inputs are constants, compare them.
919 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
920 const TypeLong *r0 = t1->is_long(); // Handy access
921 const TypeLong *r1 = t2->is_long();
922
923 if( r0->_hi < r1->_lo ) // Range is always low?
924 return TypeInt::CC_LT;
925 else if( r0->_lo > r1->_hi ) // Range is always high?
926 return TypeInt::CC_GT;
927
928 else if( r0->is_con() && r1->is_con() ) { // comparing constants?
929 assert(r0->get_con() == r1->get_con(), "must be equal");
930 return TypeInt::CC_EQ; // Equal results.
931 } else if( r0->_hi == r1->_lo ) // Range is never high?
932 return TypeInt::CC_LE;
933 else if( r0->_lo == r1->_hi ) // Range is never low?
934 return TypeInt::CC_GE;
935 return TypeInt::CC; // else use worst case results
1021 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
1022 return TypeInt::CC_GT; // different pointers
1023 }
1024 }
1025 bool xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
1026 bool xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
1027 bool unrelated_classes = false;
1028
1029 if ((p0 && p0->is_same_java_type_as(p1)) ||
1030 (k0 && k0->is_same_java_type_as(k1))) {
1031 } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
1032 (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1033 unrelated_classes = true;
1034 } else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1035 (k0 && !k1->maybe_java_subtype_of(k0))) {
1036 unrelated_classes = xklass1;
1037 } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1038 (k0 && !k0->maybe_java_subtype_of(k1))) {
1039 unrelated_classes = xklass0;
1040 }
1041 if (!unrelated_classes) {
1042 // Handle inline type arrays
1043 if ((r0->flatten_array() && r1->not_flatten_array()) ||
1044 (r1->flatten_array() && r0->not_flatten_array())) {
1045 // One type is flattened in arrays but the other type is not. Must be unrelated.
1046 unrelated_classes = true;
1047 } else if ((r0->is_not_flat() && r1->is_flat()) ||
1048 (r1->is_not_flat() && r0->is_flat())) {
1049 // One type is a non-flattened array and the other type is a flattened array. Must be unrelated.
1050 unrelated_classes = true;
1051 } else if ((r0->is_not_null_free() && r1->is_null_free()) ||
1052 (r1->is_not_null_free() && r0->is_null_free())) {
1053 // One type is a nullable array and the other type is a null-free array. Must be unrelated.
1054 unrelated_classes = true;
1055 }
1056 }
1057 if (unrelated_classes) {
1058 // The oops classes are known to be unrelated. If the joined PTRs of
1059 // two oops is not Null and not Bottom, then we are sure that one
1060 // of the two oops is non-null, and the comparison will always fail.
1061 TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1062 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1063 return TypeInt::CC_GT;
1064 }
1065 }
1066 }
1067
1068 // Known constants can be compared exactly
1069 // Null can be distinguished from any NotNull pointers
1070 // Unknown inputs makes an unknown result
1071 if( r0->singleton() ) {
1072 intptr_t bits0 = r0->get_con();
1073 if( r1->singleton() )
1074 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1075 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1076 } else if( r1->singleton() ) {
1121 if (!mirror_type) return NULL;
1122
1123 // x.getClass() == int.class can never be true (for all primitive types)
1124 // Return a ConP(NULL) node for this case.
1125 if (mirror_type->is_classless()) {
1126 return phase->makecon(TypePtr::NULL_PTR);
1127 }
1128
1129 // return the ConP(Foo.klass)
1130 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1131 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1132 }
1133
1134 //------------------------------Ideal------------------------------------------
1135 // Normalize comparisons between Java mirror loads to compare the klass instead.
1136 //
1137 // Also check for the case of comparing an unknown klass loaded from the primary
1138 // super-type array vs a known klass with no subtypes. This amounts to
1139 // checking to see an unknown klass subtypes a known klass with no subtypes;
1140 // this only happens on an exact match. We can shorten this test by 1 load.
1141 Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1142 // TODO 8284443 in(1) could be cast?
1143 if (in(1)->is_InlineType() && phase->type(in(2))->is_zero_type()) {
1144 // Null checking a scalarized but nullable inline type. Check the IsInit
1145 // input instead of the oop input to avoid keeping buffer allocations alive.
1146 return new CmpINode(in(1)->as_InlineType()->get_is_init(), phase->intcon(0));
1147 }
1148
1149 // Normalize comparisons between Java mirrors into comparisons of the low-
1150 // level klass, where a dependent load could be shortened.
1151 //
1152 // The new pattern has a nice effect of matching the same pattern used in the
1153 // fast path of instanceof/checkcast/Class.isInstance(), which allows
1154 // redundant exact type check be optimized away by GVN.
1155 // For example, in
1156 // if (x.getClass() == Foo.class) {
1157 // Foo foo = (Foo) x;
1158 // // ... use a ...
1159 // }
1160 // a CmpPNode could be shared between if_acmpne and checkcast
1161 {
1162 Node* k1 = isa_java_mirror_load(phase, in(1));
1163 Node* k2 = isa_java_mirror_load(phase, in(2));
1164 Node* conk2 = isa_const_java_mirror(phase, in(2));
1165
1166 if (k1 && (k2 || conk2)) {
1167 Node* lhs = k1;
1168 Node* rhs = (k2 != NULL) ? k2 : conk2;
1200 superklass->is_abstract()) {
1201 // Make it come out always false:
1202 this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1203 return this;
1204 }
1205 }
1206
1207 // Check for a LoadKlass from primary supertype array.
1208 // Any nested loadklass from loadklass+con must be from the p.s. array.
1209 if (ldk2->is_DecodeNKlass()) {
1210 // Keep ldk2 as DecodeN since it could be used in CmpP below.
1211 if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1212 return NULL;
1213 } else if (ldk2->Opcode() != Op_LoadKlass)
1214 return NULL;
1215
1216 // Verify that we understand the situation
1217 if (con2 != (intptr_t) superklass->super_check_offset())
1218 return NULL; // Might be element-klass loading from array klass
1219
1220 // Do not fold the subtype check to an array klass pointer comparison for [V? arrays.
1221 // [QMyValue is a subtype of [LMyValue but the klass for [QMyValue is not equal to
1222 // the klass for [LMyValue. Do not bypass the klass load from the primary supertype array.
1223 if (superklass->is_obj_array_klass() && !superklass->as_array_klass()->is_elem_null_free() &&
1224 superklass->as_array_klass()->element_klass()->is_inlinetype()) {
1225 return NULL;
1226 }
1227
1228 // If 'superklass' has no subklasses and is not an interface, then we are
1229 // assured that the only input which will pass the type check is
1230 // 'superklass' itself.
1231 //
1232 // We could be more liberal here, and allow the optimization on interfaces
1233 // which have a single implementor. This would require us to increase the
1234 // expressiveness of the add_dependency() mechanism.
1235 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
1236
1237 // Object arrays must have their base element have no subtypes
1238 while (superklass->is_obj_array_klass()) {
1239 ciType* elem = superklass->as_obj_array_klass()->element_type();
1240 superklass = elem->as_klass();
1241 }
1242 if (superklass->is_instance_klass()) {
1243 ciInstanceKlass* ik = superklass->as_instance_klass();
1244 if (ik->has_subklass() || ik->is_interface()) return NULL;
1245 // Add a dependency if there is a chance that a subclass will be added later.
1246 if (!ik->is_final()) {
1247 phase->C->dependencies()->assert_leaf_type(ik);
1351 if( t2_value_as_double == (double)t2_value_as_float ) {
1352 // Test value can be represented as a float
1353 // Eliminate the conversion to double and create new comparison
1354 Node *new_in1 = in(idx_f2d)->in(1);
1355 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1356 if( idx_f2d != 1 ) { // Must flip args to match original order
1357 Node *tmp = new_in1;
1358 new_in1 = new_in2;
1359 new_in2 = tmp;
1360 }
1361 CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1362 ? new CmpF3Node( new_in1, new_in2 )
1363 : new CmpFNode ( new_in1, new_in2 ) ;
1364 return new_cmp; // Changed to CmpFNode
1365 }
1366 // Testing value required the precision of a double
1367 }
1368 return NULL; // No change
1369 }
1370
1371 //=============================================================================
1372 //------------------------------Value------------------------------------------
1373 const Type* FlatArrayCheckNode::Value(PhaseGVN* phase) const {
1374 bool all_not_flat = true;
1375 for (uint i = ArrayOrKlass; i < req(); ++i) {
1376 const Type* t = phase->type(in(i));
1377 if (t == Type::TOP) {
1378 return Type::TOP;
1379 }
1380 if (t->is_ptr()->is_flat()) {
1381 // One of the input arrays is flat, check always passes
1382 return TypeInt::CC_EQ;
1383 } else if (!t->is_ptr()->is_not_flat()) {
1384 // One of the input arrays might be flat
1385 all_not_flat = false;
1386 }
1387 }
1388 if (all_not_flat) {
1389 // None of the input arrays can be flat, check always fails
1390 return TypeInt::CC_GT;
1391 }
1392 return TypeInt::CC;
1393 }
1394
1395 //------------------------------Ideal------------------------------------------
1396 Node* FlatArrayCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1397 bool changed = false;
1398 // Remove inputs that are known to be non-flat
1399 for (uint i = ArrayOrKlass; i < req(); ++i) {
1400 const Type* t = phase->type(in(i));
1401 if (t->isa_ptr() && t->is_ptr()->is_not_flat()) {
1402 del_req(i--);
1403 changed = true;
1404 }
1405 }
1406 return changed ? this : NULL;
1407 }
1408
1409 //=============================================================================
1410 //------------------------------cc2logical-------------------------------------
1411 // Convert a condition code type to a logical type
1412 const Type *BoolTest::cc2logical( const Type *CC ) const {
1413 if( CC == Type::TOP ) return Type::TOP;
1414 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
1415 const TypeInt *ti = CC->is_int();
1416 if( ti->is_con() ) { // Only 1 kind of condition codes set?
1417 // Match low order 2 bits
1418 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1419 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
1420 return TypeInt::make(tmp); // Boolean result
1421 }
1422
1423 if( CC == TypeInt::CC_GE ) {
1424 if( _test == ge ) return TypeInt::ONE;
1425 if( _test == lt ) return TypeInt::ZERO;
1426 }
1427 if( CC == TypeInt::CC_LE ) {
|