< prev index next >

src/hotspot/share/opto/subnode.cpp

Print this page

  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.

 903     switch (in(1)->Opcode()) {
 904     case Op_CmpU3:              // Collapse a CmpU3/CmpI into a CmpU
 905       return new CmpUNode(in(1)->in(1),in(1)->in(2));
 906     case Op_CmpL3:              // Collapse a CmpL3/CmpI into a CmpL
 907       return new CmpLNode(in(1)->in(1),in(1)->in(2));
 908     case Op_CmpUL3:             // Collapse a CmpUL3/CmpI into a CmpUL
 909       return new CmpULNode(in(1)->in(1),in(1)->in(2));
 910     case Op_CmpF3:              // Collapse a CmpF3/CmpI into a CmpF
 911       return new CmpFNode(in(1)->in(1),in(1)->in(2));
 912     case Op_CmpD3:              // Collapse a CmpD3/CmpI into a CmpD
 913       return new CmpDNode(in(1)->in(1),in(1)->in(2));
 914     //case Op_SubI:
 915       // If (x - y) cannot overflow, then ((x - y) <?> 0)
 916       // can be turned into (x <?> y).
 917       // This is handled (with more general cases) by Ideal_sub_algebra.
 918     }
 919   }
 920   return nullptr;                  // No change
 921 }
 922 
 923 Node *CmpLNode::Ideal( PhaseGVN *phase, bool can_reshape ) {







 924   const TypeLong *t2 = phase->type(in(2))->isa_long();
 925   if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
 926     const jlong con = t2->get_con();
 927     if (con >= min_jint && con <= max_jint) {
 928       return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
 929     }
 930   }
 931   return nullptr;
 932 }
 933 

























 934 //=============================================================================
 935 // Simplify a CmpL (compare 2 longs ) node, based on local information.
 936 // If both inputs are constants, compare them.
 937 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
 938   const TypeLong *r0 = t1->is_long(); // Handy access
 939   const TypeLong *r1 = t2->is_long();
 940 
 941   if( r0->_hi < r1->_lo )       // Range is always low?
 942     return TypeInt::CC_LT;
 943   else if( r0->_lo > r1->_hi )  // Range is always high?
 944     return TypeInt::CC_GT;
 945 
 946   else if( r0->is_con() && r1->is_con() ) { // comparing constants?
 947     assert(r0->get_con() == r1->get_con(), "must be equal");
 948     return TypeInt::CC_EQ;      // Equal results.
 949   } else if( r0->_hi == r1->_lo ) // Range is never high?
 950     return TypeInt::CC_LE;
 951   else if( r0->_lo == r1->_hi ) // Range is never low?
 952     return TypeInt::CC_GE;
 953 

1050       if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, nullptr)) {
1051         return TypeInt::CC_GT;  // different pointers
1052       }
1053     }
1054     bool    xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
1055     bool    xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
1056     bool unrelated_classes = false;
1057 
1058     if ((p0 && p0->is_same_java_type_as(p1)) ||
1059         (k0 && k0->is_same_java_type_as(k1))) {
1060     } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
1061                (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1062       unrelated_classes = true;
1063     } else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1064                (k0 && !k1->maybe_java_subtype_of(k0))) {
1065       unrelated_classes = xklass1;
1066     } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1067                (k0 && !k0->maybe_java_subtype_of(k1))) {
1068       unrelated_classes = xklass0;
1069     }
1070 















1071     if (unrelated_classes) {
1072       // The oops classes are known to be unrelated. If the joined PTRs of
1073       // two oops is not Null and not Bottom, then we are sure that one
1074       // of the two oops is non-null, and the comparison will always fail.
1075       TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1076       if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1077         return TypeInt::CC_GT;
1078       }
1079     }
1080   }
1081 
1082   // Known constants can be compared exactly
1083   // Null can be distinguished from any NotNull pointers
1084   // Unknown inputs makes an unknown result
1085   if( r0->singleton() ) {
1086     intptr_t bits0 = r0->get_con();
1087     if( r1->singleton() )
1088       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1089     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1090   } else if( r1->singleton() ) {

1135   if (!mirror_type) return nullptr;
1136 
1137   // x.getClass() == int.class can never be true (for all primitive types)
1138   // Return a ConP(null) node for this case.
1139   if (mirror_type->is_classless()) {
1140     return phase->makecon(TypePtr::NULL_PTR);
1141   }
1142 
1143   // return the ConP(Foo.klass)
1144   assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1145   return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1146 }
1147 
1148 //------------------------------Ideal------------------------------------------
1149 // Normalize comparisons between Java mirror loads to compare the klass instead.
1150 //
1151 // Also check for the case of comparing an unknown klass loaded from the primary
1152 // super-type array vs a known klass with no subtypes.  This amounts to
1153 // checking to see an unknown klass subtypes a known klass with no subtypes;
1154 // this only happens on an exact match.  We can shorten this test by 1 load.
1155 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {







1156   // Normalize comparisons between Java mirrors into comparisons of the low-
1157   // level klass, where a dependent load could be shortened.
1158   //
1159   // The new pattern has a nice effect of matching the same pattern used in the
1160   // fast path of instanceof/checkcast/Class.isInstance(), which allows
1161   // redundant exact type check be optimized away by GVN.
1162   // For example, in
1163   //   if (x.getClass() == Foo.class) {
1164   //     Foo foo = (Foo) x;
1165   //     // ... use a ...
1166   //   }
1167   // a CmpPNode could be shared between if_acmpne and checkcast
1168   {
1169     Node* k1 = isa_java_mirror_load(phase, in(1));
1170     Node* k2 = isa_java_mirror_load(phase, in(2));
1171     Node* conk2 = isa_const_java_mirror(phase, in(2));
1172 
1173     if (k1 && (k2 || conk2)) {


1174       Node* lhs = k1;
1175       Node* rhs = (k2 != nullptr) ? k2 : conk2;
1176       set_req_X(1, lhs, phase);
1177       set_req_X(2, rhs, phase);
1178       return this;
1179     }
1180   }
1181 
1182   // Constant pointer on right?
1183   const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
1184   if (t2 == nullptr || !t2->klass_is_exact())
1185     return nullptr;
1186   // Get the constant klass we are comparing to.
1187   ciKlass* superklass = t2->exact_klass();
1188 
1189   // Now check for LoadKlass on left.
1190   Node* ldk1 = in(1);
1191   if (ldk1->is_DecodeNKlass()) {
1192     ldk1 = ldk1->in(1);
1193     if (ldk1->Opcode() != Op_LoadNKlass )

1207         superklass->is_abstract()) {
1208       // Make it come out always false:
1209       this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1210       return this;
1211     }
1212   }
1213 
1214   // Check for a LoadKlass from primary supertype array.
1215   // Any nested loadklass from loadklass+con must be from the p.s. array.
1216   if (ldk2->is_DecodeNKlass()) {
1217     // Keep ldk2 as DecodeN since it could be used in CmpP below.
1218     if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1219       return nullptr;
1220   } else if (ldk2->Opcode() != Op_LoadKlass)
1221     return nullptr;
1222 
1223   // Verify that we understand the situation
1224   if (con2 != (intptr_t) superklass->super_check_offset())
1225     return nullptr;                // Might be element-klass loading from array klass
1226 







1227   // If 'superklass' has no subklasses and is not an interface, then we are
1228   // assured that the only input which will pass the type check is
1229   // 'superklass' itself.
1230   //
1231   // We could be more liberal here, and allow the optimization on interfaces
1232   // which have a single implementor.  This would require us to increase the
1233   // expressiveness of the add_dependency() mechanism.
1234   // %%% Do this after we fix TypeOopPtr:  Deps are expressive enough now.
1235 
1236   // Object arrays must have their base element have no subtypes
1237   while (superklass->is_obj_array_klass()) {
1238     ciType* elem = superklass->as_obj_array_klass()->element_type();
1239     superklass = elem->as_klass();
1240   }
1241   if (superklass->is_instance_klass()) {
1242     ciInstanceKlass* ik = superklass->as_instance_klass();
1243     if (ik->has_subklass() || ik->is_interface())  return nullptr;
1244     // Add a dependency if there is a chance that a subclass will be added later.
1245     if (!ik->is_final()) {
1246       phase->C->dependencies()->assert_leaf_type(ik);

1350     if( t2_value_as_double == (double)t2_value_as_float ) {
1351       // Test value can be represented as a float
1352       // Eliminate the conversion to double and create new comparison
1353       Node *new_in1 = in(idx_f2d)->in(1);
1354       Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1355       if( idx_f2d != 1 ) {      // Must flip args to match original order
1356         Node *tmp = new_in1;
1357         new_in1 = new_in2;
1358         new_in2 = tmp;
1359       }
1360       CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1361         ? new CmpF3Node( new_in1, new_in2 )
1362         : new CmpFNode ( new_in1, new_in2 ) ;
1363       return new_cmp;           // Changed to CmpFNode
1364     }
1365     // Testing value required the precision of a double
1366   }
1367   return nullptr;                  // No change
1368 }
1369 





































1370 
1371 //=============================================================================
1372 //------------------------------cc2logical-------------------------------------
1373 // Convert a condition code type to a logical type
1374 const Type *BoolTest::cc2logical( const Type *CC ) const {
1375   if( CC == Type::TOP ) return Type::TOP;
1376   if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
1377   const TypeInt *ti = CC->is_int();
1378   if( ti->is_con() ) {          // Only 1 kind of condition codes set?
1379     // Match low order 2 bits
1380     int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1381     if( _test & 4 ) tmp = 1-tmp;     // Optionally complement result
1382     return TypeInt::make(tmp);       // Boolean result
1383   }
1384 
1385   if( CC == TypeInt::CC_GE ) {
1386     if( _test == ge ) return TypeInt::ONE;
1387     if( _test == lt ) return TypeInt::ZERO;
1388   }
1389   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.

 904     switch (in(1)->Opcode()) {
 905     case Op_CmpU3:              // Collapse a CmpU3/CmpI into a CmpU
 906       return new CmpUNode(in(1)->in(1),in(1)->in(2));
 907     case Op_CmpL3:              // Collapse a CmpL3/CmpI into a CmpL
 908       return new CmpLNode(in(1)->in(1),in(1)->in(2));
 909     case Op_CmpUL3:             // Collapse a CmpUL3/CmpI into a CmpUL
 910       return new CmpULNode(in(1)->in(1),in(1)->in(2));
 911     case Op_CmpF3:              // Collapse a CmpF3/CmpI into a CmpF
 912       return new CmpFNode(in(1)->in(1),in(1)->in(2));
 913     case Op_CmpD3:              // Collapse a CmpD3/CmpI into a CmpD
 914       return new CmpDNode(in(1)->in(1),in(1)->in(2));
 915     //case Op_SubI:
 916       // If (x - y) cannot overflow, then ((x - y) <?> 0)
 917       // can be turned into (x <?> y).
 918       // This is handled (with more general cases) by Ideal_sub_algebra.
 919     }
 920   }
 921   return nullptr;                  // No change
 922 }
 923 
 924 //------------------------------Ideal------------------------------------------
 925 Node* CmpLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
 926   Node* a = nullptr;
 927   Node* b = nullptr;
 928   if (is_double_null_check(phase, a, b) && (phase->type(a)->is_zero_type() || phase->type(b)->is_zero_type())) {
 929     // Degraded to a simple null check, use old acmp
 930     return new CmpPNode(a, b);
 931   }
 932   const TypeLong *t2 = phase->type(in(2))->isa_long();
 933   if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
 934     const jlong con = t2->get_con();
 935     if (con >= min_jint && con <= max_jint) {
 936       return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
 937     }
 938   }
 939   return nullptr;
 940 }
 941 
 942 // Match double null check emitted by Compile::optimize_acmp()
 943 bool CmpLNode::is_double_null_check(PhaseGVN* phase, Node*& a, Node*& b) const {
 944   if (in(1)->Opcode() == Op_OrL &&
 945       in(1)->in(1)->Opcode() == Op_CastP2X &&
 946       in(1)->in(2)->Opcode() == Op_CastP2X &&
 947       in(2)->bottom_type()->is_zero_type()) {
 948     assert(EnableValhalla, "unexpected double null check");
 949     a = in(1)->in(1)->in(1);
 950     b = in(1)->in(2)->in(1);
 951     return true;
 952   }
 953   return false;
 954 }
 955 
 956 //------------------------------Value------------------------------------------
 957 const Type* CmpLNode::Value(PhaseGVN* phase) const {
 958   Node* a = nullptr;
 959   Node* b = nullptr;
 960   if (is_double_null_check(phase, a, b) && (!phase->type(a)->maybe_null() || !phase->type(b)->maybe_null())) {
 961     // One operand is never nullptr, emit constant false
 962     return TypeInt::CC_GT;
 963   }
 964   return SubNode::Value(phase);
 965 }
 966 
 967 //=============================================================================
 968 // Simplify a CmpL (compare 2 longs ) node, based on local information.
 969 // If both inputs are constants, compare them.
 970 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
 971   const TypeLong *r0 = t1->is_long(); // Handy access
 972   const TypeLong *r1 = t2->is_long();
 973 
 974   if( r0->_hi < r1->_lo )       // Range is always low?
 975     return TypeInt::CC_LT;
 976   else if( r0->_lo > r1->_hi )  // Range is always high?
 977     return TypeInt::CC_GT;
 978 
 979   else if( r0->is_con() && r1->is_con() ) { // comparing constants?
 980     assert(r0->get_con() == r1->get_con(), "must be equal");
 981     return TypeInt::CC_EQ;      // Equal results.
 982   } else if( r0->_hi == r1->_lo ) // Range is never high?
 983     return TypeInt::CC_LE;
 984   else if( r0->_lo == r1->_hi ) // Range is never low?
 985     return TypeInt::CC_GE;
 986 

1083       if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, nullptr)) {
1084         return TypeInt::CC_GT;  // different pointers
1085       }
1086     }
1087     bool    xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
1088     bool    xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
1089     bool unrelated_classes = false;
1090 
1091     if ((p0 && p0->is_same_java_type_as(p1)) ||
1092         (k0 && k0->is_same_java_type_as(k1))) {
1093     } else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
1094                (k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1095       unrelated_classes = true;
1096     } else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1097                (k0 && !k1->maybe_java_subtype_of(k0))) {
1098       unrelated_classes = xklass1;
1099     } else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1100                (k0 && !k0->maybe_java_subtype_of(k1))) {
1101       unrelated_classes = xklass0;
1102     }
1103     if (!unrelated_classes) {
1104       // Handle inline type arrays
1105       if ((r0->flat_in_array() && r1->not_flat_in_array()) ||
1106           (r1->flat_in_array() && r0->not_flat_in_array())) {
1107         // One type is in flat arrays but the other type is not. Must be unrelated.
1108         unrelated_classes = true;
1109       } else if ((r0->is_not_flat() && r1->is_flat()) ||
1110                  (r1->is_not_flat() && r0->is_flat())) {
1111         // One type is a non-flat array and the other type is a flat array. Must be unrelated.
1112         unrelated_classes = true;
1113       } else if ((r0->is_not_null_free() && r1->is_null_free()) ||
1114                  (r1->is_not_null_free() && r0->is_null_free())) {
1115         // One type is a nullable array and the other type is a null-free array. Must be unrelated.
1116         unrelated_classes = true;
1117       }
1118     }
1119     if (unrelated_classes) {
1120       // The oops classes are known to be unrelated. If the joined PTRs of
1121       // two oops is not Null and not Bottom, then we are sure that one
1122       // of the two oops is non-null, and the comparison will always fail.
1123       TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1124       if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1125         return TypeInt::CC_GT;
1126       }
1127     }
1128   }
1129 
1130   // Known constants can be compared exactly
1131   // Null can be distinguished from any NotNull pointers
1132   // Unknown inputs makes an unknown result
1133   if( r0->singleton() ) {
1134     intptr_t bits0 = r0->get_con();
1135     if( r1->singleton() )
1136       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1137     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1138   } else if( r1->singleton() ) {

1183   if (!mirror_type) return nullptr;
1184 
1185   // x.getClass() == int.class can never be true (for all primitive types)
1186   // Return a ConP(null) node for this case.
1187   if (mirror_type->is_classless()) {
1188     return phase->makecon(TypePtr::NULL_PTR);
1189   }
1190 
1191   // return the ConP(Foo.klass)
1192   assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1193   return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1194 }
1195 
1196 //------------------------------Ideal------------------------------------------
1197 // Normalize comparisons between Java mirror loads to compare the klass instead.
1198 //
1199 // Also check for the case of comparing an unknown klass loaded from the primary
1200 // super-type array vs a known klass with no subtypes.  This amounts to
1201 // checking to see an unknown klass subtypes a known klass with no subtypes;
1202 // this only happens on an exact match.  We can shorten this test by 1 load.
1203 Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1204   // TODO 8284443 in(1) could be cast?
1205   if (in(1)->is_InlineType() && phase->type(in(2))->is_zero_type()) {
1206     // Null checking a scalarized but nullable inline type. Check the null marker
1207     // input instead of the oop input to avoid keeping buffer allocations alive.
1208     return new CmpINode(in(1)->as_InlineType()->get_null_marker(), phase->intcon(0));
1209   }
1210 
1211   // Normalize comparisons between Java mirrors into comparisons of the low-
1212   // level klass, where a dependent load could be shortened.
1213   //
1214   // The new pattern has a nice effect of matching the same pattern used in the
1215   // fast path of instanceof/checkcast/Class.isInstance(), which allows
1216   // redundant exact type check be optimized away by GVN.
1217   // For example, in
1218   //   if (x.getClass() == Foo.class) {
1219   //     Foo foo = (Foo) x;
1220   //     // ... use a ...
1221   //   }
1222   // a CmpPNode could be shared between if_acmpne and checkcast
1223   {
1224     Node* k1 = isa_java_mirror_load(phase, in(1));
1225     Node* k2 = isa_java_mirror_load(phase, in(2));
1226     Node* conk2 = isa_const_java_mirror(phase, in(2));
1227 
1228     // TODO 8366668 add a test for this. Improve this condition
1229     bool doIt = (conk2 && !phase->type(conk2)->isa_aryklassptr());
1230     if (k1 && (k2 || conk2) && doIt) {
1231       Node* lhs = k1;
1232       Node* rhs = (k2 != nullptr) ? k2 : conk2;
1233       set_req_X(1, lhs, phase);
1234       set_req_X(2, rhs, phase);
1235       return this;
1236     }
1237   }
1238 
1239   // Constant pointer on right?
1240   const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
1241   if (t2 == nullptr || !t2->klass_is_exact())
1242     return nullptr;
1243   // Get the constant klass we are comparing to.
1244   ciKlass* superklass = t2->exact_klass();
1245 
1246   // Now check for LoadKlass on left.
1247   Node* ldk1 = in(1);
1248   if (ldk1->is_DecodeNKlass()) {
1249     ldk1 = ldk1->in(1);
1250     if (ldk1->Opcode() != Op_LoadNKlass )

1264         superklass->is_abstract()) {
1265       // Make it come out always false:
1266       this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1267       return this;
1268     }
1269   }
1270 
1271   // Check for a LoadKlass from primary supertype array.
1272   // Any nested loadklass from loadklass+con must be from the p.s. array.
1273   if (ldk2->is_DecodeNKlass()) {
1274     // Keep ldk2 as DecodeN since it could be used in CmpP below.
1275     if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1276       return nullptr;
1277   } else if (ldk2->Opcode() != Op_LoadKlass)
1278     return nullptr;
1279 
1280   // Verify that we understand the situation
1281   if (con2 != (intptr_t) superklass->super_check_offset())
1282     return nullptr;                // Might be element-klass loading from array klass
1283 
1284   // Do not fold the subtype check to an array klass pointer comparison for null-able inline type arrays
1285   // because null-free [LMyValue <: null-able [LMyValue but the klasses are different. Perform a full test.
1286   if (superklass->is_obj_array_klass() && !superklass->as_array_klass()->is_elem_null_free() &&
1287       superklass->as_array_klass()->element_klass()->is_inlinetype()) {
1288     return nullptr;
1289   }
1290 
1291   // If 'superklass' has no subklasses and is not an interface, then we are
1292   // assured that the only input which will pass the type check is
1293   // 'superklass' itself.
1294   //
1295   // We could be more liberal here, and allow the optimization on interfaces
1296   // which have a single implementor.  This would require us to increase the
1297   // expressiveness of the add_dependency() mechanism.
1298   // %%% Do this after we fix TypeOopPtr:  Deps are expressive enough now.
1299 
1300   // Object arrays must have their base element have no subtypes
1301   while (superklass->is_obj_array_klass()) {
1302     ciType* elem = superklass->as_obj_array_klass()->element_type();
1303     superklass = elem->as_klass();
1304   }
1305   if (superklass->is_instance_klass()) {
1306     ciInstanceKlass* ik = superklass->as_instance_klass();
1307     if (ik->has_subklass() || ik->is_interface())  return nullptr;
1308     // Add a dependency if there is a chance that a subclass will be added later.
1309     if (!ik->is_final()) {
1310       phase->C->dependencies()->assert_leaf_type(ik);

1414     if( t2_value_as_double == (double)t2_value_as_float ) {
1415       // Test value can be represented as a float
1416       // Eliminate the conversion to double and create new comparison
1417       Node *new_in1 = in(idx_f2d)->in(1);
1418       Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1419       if( idx_f2d != 1 ) {      // Must flip args to match original order
1420         Node *tmp = new_in1;
1421         new_in1 = new_in2;
1422         new_in2 = tmp;
1423       }
1424       CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1425         ? new CmpF3Node( new_in1, new_in2 )
1426         : new CmpFNode ( new_in1, new_in2 ) ;
1427       return new_cmp;           // Changed to CmpFNode
1428     }
1429     // Testing value required the precision of a double
1430   }
1431   return nullptr;                  // No change
1432 }
1433 
1434 //=============================================================================
1435 //------------------------------Value------------------------------------------
1436 const Type* FlatArrayCheckNode::Value(PhaseGVN* phase) const {
1437   bool all_not_flat = true;
1438   for (uint i = ArrayOrKlass; i < req(); ++i) {
1439     const Type* t = phase->type(in(i));
1440     if (t == Type::TOP) {
1441       return Type::TOP;
1442     }
1443     if (t->is_ptr()->is_flat()) {
1444       // One of the input arrays is flat, check always passes
1445       return TypeInt::CC_EQ;
1446     } else if (!t->is_ptr()->is_not_flat()) {
1447       // One of the input arrays might be flat
1448       all_not_flat = false;
1449     }
1450   }
1451   if (all_not_flat) {
1452     // None of the input arrays can be flat, check always fails
1453     return TypeInt::CC_GT;
1454   }
1455   return TypeInt::CC;
1456 }
1457 
1458 //------------------------------Ideal------------------------------------------
1459 Node* FlatArrayCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1460   bool changed = false;
1461   // Remove inputs that are known to be non-flat
1462   for (uint i = ArrayOrKlass; i < req(); ++i) {
1463     const Type* t = phase->type(in(i));
1464     if (t->isa_ptr() && t->is_ptr()->is_not_flat()) {
1465       del_req(i--);
1466       changed = true;
1467     }
1468   }
1469   return changed ? this : nullptr;
1470 }
1471 
1472 //=============================================================================
1473 //------------------------------cc2logical-------------------------------------
1474 // Convert a condition code type to a logical type
1475 const Type *BoolTest::cc2logical( const Type *CC ) const {
1476   if( CC == Type::TOP ) return Type::TOP;
1477   if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
1478   const TypeInt *ti = CC->is_int();
1479   if( ti->is_con() ) {          // Only 1 kind of condition codes set?
1480     // Match low order 2 bits
1481     int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1482     if( _test & 4 ) tmp = 1-tmp;     // Optionally complement result
1483     return TypeInt::make(tmp);       // Boolean result
1484   }
1485 
1486   if( CC == TypeInt::CC_GE ) {
1487     if( _test == ge ) return TypeInt::ONE;
1488     if( _test == lt ) return TypeInt::ZERO;
1489   }
1490   if( CC == TypeInt::CC_LE ) {
< prev index next >