< prev index next >

src/hotspot/share/opto/subnode.cpp

Print this page




 706 
 707 //------------------------------Idealize---------------------------------------
 708 Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
 709   if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
 710     switch (in(1)->Opcode()) {
 711     case Op_CmpL3:              // Collapse a CmpL3/CmpI into a CmpL
 712       return new CmpLNode(in(1)->in(1),in(1)->in(2));
 713     case Op_CmpF3:              // Collapse a CmpF3/CmpI into a CmpF
 714       return new CmpFNode(in(1)->in(1),in(1)->in(2));
 715     case Op_CmpD3:              // Collapse a CmpD3/CmpI into a CmpD
 716       return new CmpDNode(in(1)->in(1),in(1)->in(2));
 717     //case Op_SubI:
 718       // If (x - y) cannot overflow, then ((x - y) <?> 0)
 719       // can be turned into (x <?> y).
 720       // This is handled (with more general cases) by Ideal_sub_algebra.
 721     }
 722   }
 723   return NULL;                  // No change
 724 }
 725 



































 726 
 727 //=============================================================================
 728 // Simplify a CmpL (compare 2 longs ) node, based on local information.
 729 // If both inputs are constants, compare them.
 730 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
 731   const TypeLong *r0 = t1->is_long(); // Handy access
 732   const TypeLong *r1 = t2->is_long();
 733 
 734   if( r0->_hi < r1->_lo )       // Range is always low?
 735     return TypeInt::CC_LT;
 736   else if( r0->_lo > r1->_hi )  // Range is always high?
 737     return TypeInt::CC_GT;
 738 
 739   else if( r0->is_con() && r1->is_con() ) { // comparing constants?
 740     assert(r0->get_con() == r1->get_con(), "must be equal");
 741     return TypeInt::CC_EQ;      // Equal results.
 742   } else if( r0->_hi == r1->_lo ) // Range is never high?
 743     return TypeInt::CC_LE;
 744   else if( r0->_lo == r1->_hi ) // Range is never low?
 745     return TypeInt::CC_GE;


 925   if (!mirror_type) return NULL;
 926 
 927   // x.getClass() == int.class can never be true (for all primitive types)
 928   // Return a ConP(NULL) node for this case.
 929   if (mirror_type->is_classless()) {
 930     return phase->makecon(TypePtr::NULL_PTR);
 931   }
 932 
 933   // return the ConP(Foo.klass)
 934   assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
 935   return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass()));
 936 }
 937 
 938 //------------------------------Ideal------------------------------------------
 939 // Normalize comparisons between Java mirror loads to compare the klass instead.
 940 //
 941 // Also check for the case of comparing an unknown klass loaded from the primary
 942 // super-type array vs a known klass with no subtypes.  This amounts to
 943 // checking to see an unknown klass subtypes a known klass with no subtypes;
 944 // this only happens on an exact match.  We can shorten this test by 1 load.
 945 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
 946   // Normalize comparisons between Java mirrors into comparisons of the low-
 947   // level klass, where a dependent load could be shortened.
 948   //
 949   // The new pattern has a nice effect of matching the same pattern used in the
 950   // fast path of instanceof/checkcast/Class.isInstance(), which allows
 951   // redundant exact type check be optimized away by GVN.
 952   // For example, in
 953   //   if (x.getClass() == Foo.class) {
 954   //     Foo foo = (Foo) x;
 955   //     // ... use a ...
 956   //   }
 957   // a CmpPNode could be shared between if_acmpne and checkcast
 958   {
 959     Node* k1 = isa_java_mirror_load(phase, in(1));
 960     Node* k2 = isa_java_mirror_load(phase, in(2));
 961     Node* conk2 = isa_const_java_mirror(phase, in(2));
 962 
 963     if (k1 && (k2 || conk2)) {
 964       Node* lhs = k1;
 965       Node* rhs = (k2 != NULL) ? k2 : conk2;


1002     if (superklass->is_interface() ||
1003         superklass->is_abstract()) {
1004       // Make it come out always false:
1005       this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1006       return this;
1007     }
1008   }
1009 
1010   // Check for a LoadKlass from primary supertype array.
1011   // Any nested loadklass from loadklass+con must be from the p.s. array.
1012   if (ldk2->is_DecodeNKlass()) {
1013     // Keep ldk2 as DecodeN since it could be used in CmpP below.
1014     if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1015       return NULL;
1016   } else if (ldk2->Opcode() != Op_LoadKlass)
1017     return NULL;
1018 
1019   // Verify that we understand the situation
1020   if (con2 != (intptr_t) superklass->super_check_offset())
1021     return NULL;                // Might be element-klass loading from array klass










1022 
1023   // If 'superklass' has no subklasses and is not an interface, then we are
1024   // assured that the only input which will pass the type check is
1025   // 'superklass' itself.
1026   //
1027   // We could be more liberal here, and allow the optimization on interfaces
1028   // which have a single implementor.  This would require us to increase the
1029   // expressiveness of the add_dependency() mechanism.
1030   // %%% Do this after we fix TypeOopPtr:  Deps are expressive enough now.
1031 
1032   // Object arrays must have their base element have no subtypes
1033   while (superklass->is_obj_array_klass()) {
1034     ciType* elem = superklass->as_obj_array_klass()->element_type();
1035     superklass = elem->as_klass();
1036   }
1037   if (superklass->is_instance_klass()) {
1038     ciInstanceKlass* ik = superklass->as_instance_klass();
1039     if (ik->has_subklass() || ik->is_interface())  return NULL;
1040     // Add a dependency if there is a chance that a subclass will be added later.
1041     if (!ik->is_final()) {




 706 
 707 //------------------------------Idealize---------------------------------------
 708 Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
 709   if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
 710     switch (in(1)->Opcode()) {
 711     case Op_CmpL3:              // Collapse a CmpL3/CmpI into a CmpL
 712       return new CmpLNode(in(1)->in(1),in(1)->in(2));
 713     case Op_CmpF3:              // Collapse a CmpF3/CmpI into a CmpF
 714       return new CmpFNode(in(1)->in(1),in(1)->in(2));
 715     case Op_CmpD3:              // Collapse a CmpD3/CmpI into a CmpD
 716       return new CmpDNode(in(1)->in(1),in(1)->in(2));
 717     //case Op_SubI:
 718       // If (x - y) cannot overflow, then ((x - y) <?> 0)
 719       // can be turned into (x <?> y).
 720       // This is handled (with more general cases) by Ideal_sub_algebra.
 721     }
 722   }
 723   return NULL;                  // No change
 724 }
 725 
 726 //------------------------------Ideal------------------------------------------
 727 Node* CmpLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
 728   Node* a = NULL;
 729   Node* b = NULL;
 730   if (is_double_null_check(phase, a, b) && (phase->type(a)->is_zero_type() || phase->type(b)->is_zero_type())) {
 731     // Degraded to a simple null check, use old acmp
 732     return new CmpPNode(a, b);
 733   }
 734   return NULL;
 735 }
 736 
 737 // Match double null check emitted by Compile::optimize_acmp()
 738 bool CmpLNode::is_double_null_check(PhaseGVN* phase, Node*& a, Node*& b) const {
 739   if (in(1)->Opcode() == Op_OrL &&
 740       in(1)->in(1)->Opcode() == Op_CastP2X &&
 741       in(1)->in(2)->Opcode() == Op_CastP2X &&
 742       in(2)->bottom_type()->is_zero_type()) {
 743     assert(EnableValhalla, "unexpected double null check");
 744     a = in(1)->in(1)->in(1);
 745     b = in(1)->in(2)->in(1);
 746     return true;
 747   }
 748   return false;
 749 }
 750 
 751 //------------------------------Value------------------------------------------
 752 const Type* CmpLNode::Value(PhaseGVN* phase) const {
 753   Node* a = NULL;
 754   Node* b = NULL;
 755   if (is_double_null_check(phase, a, b) && (!phase->type(a)->maybe_null() || !phase->type(b)->maybe_null())) {
 756     // One operand is never NULL, emit constant false
 757     return TypeInt::CC_GT;
 758   }
 759   return SubNode::Value(phase);
 760 }
 761 
 762 //=============================================================================
 763 // Simplify a CmpL (compare 2 longs ) node, based on local information.
 764 // If both inputs are constants, compare them.
 765 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
 766   const TypeLong *r0 = t1->is_long(); // Handy access
 767   const TypeLong *r1 = t2->is_long();
 768 
 769   if( r0->_hi < r1->_lo )       // Range is always low?
 770     return TypeInt::CC_LT;
 771   else if( r0->_lo > r1->_hi )  // Range is always high?
 772     return TypeInt::CC_GT;
 773 
 774   else if( r0->is_con() && r1->is_con() ) { // comparing constants?
 775     assert(r0->get_con() == r1->get_con(), "must be equal");
 776     return TypeInt::CC_EQ;      // Equal results.
 777   } else if( r0->_hi == r1->_lo ) // Range is never high?
 778     return TypeInt::CC_LE;
 779   else if( r0->_lo == r1->_hi ) // Range is never low?
 780     return TypeInt::CC_GE;


 960   if (!mirror_type) return NULL;
 961 
 962   // x.getClass() == int.class can never be true (for all primitive types)
 963   // Return a ConP(NULL) node for this case.
 964   if (mirror_type->is_classless()) {
 965     return phase->makecon(TypePtr::NULL_PTR);
 966   }
 967 
 968   // return the ConP(Foo.klass)
 969   assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
 970   return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass()));
 971 }
 972 
 973 //------------------------------Ideal------------------------------------------
 974 // Normalize comparisons between Java mirror loads to compare the klass instead.
 975 //
 976 // Also check for the case of comparing an unknown klass loaded from the primary
 977 // super-type array vs a known klass with no subtypes.  This amounts to
 978 // checking to see an unknown klass subtypes a known klass with no subtypes;
 979 // this only happens on an exact match.  We can shorten this test by 1 load.
 980 Node* CmpPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 981   // Normalize comparisons between Java mirrors into comparisons of the low-
 982   // level klass, where a dependent load could be shortened.
 983   //
 984   // The new pattern has a nice effect of matching the same pattern used in the
 985   // fast path of instanceof/checkcast/Class.isInstance(), which allows
 986   // redundant exact type check be optimized away by GVN.
 987   // For example, in
 988   //   if (x.getClass() == Foo.class) {
 989   //     Foo foo = (Foo) x;
 990   //     // ... use a ...
 991   //   }
 992   // a CmpPNode could be shared between if_acmpne and checkcast
 993   {
 994     Node* k1 = isa_java_mirror_load(phase, in(1));
 995     Node* k2 = isa_java_mirror_load(phase, in(2));
 996     Node* conk2 = isa_const_java_mirror(phase, in(2));
 997 
 998     if (k1 && (k2 || conk2)) {
 999       Node* lhs = k1;
1000       Node* rhs = (k2 != NULL) ? k2 : conk2;


1037     if (superklass->is_interface() ||
1038         superklass->is_abstract()) {
1039       // Make it come out always false:
1040       this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1041       return this;
1042     }
1043   }
1044 
1045   // Check for a LoadKlass from primary supertype array.
1046   // Any nested loadklass from loadklass+con must be from the p.s. array.
1047   if (ldk2->is_DecodeNKlass()) {
1048     // Keep ldk2 as DecodeN since it could be used in CmpP below.
1049     if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1050       return NULL;
1051   } else if (ldk2->Opcode() != Op_LoadKlass)
1052     return NULL;
1053 
1054   // Verify that we understand the situation
1055   if (con2 != (intptr_t) superklass->super_check_offset())
1056     return NULL;                // Might be element-klass loading from array klass
1057 
1058   // Do not fold the subtype check to an array klass pointer comparison for [V? arrays.
1059   // [V is a subtype of [V? but the klass for [V is not equal to the klass for [V?. Perform a full test.
1060   if (superklass->is_obj_array_klass()) {
1061     ciObjArrayKlass* ak = superklass->as_obj_array_klass();
1062     if (!ak->storage_properties().is_null_free() && ak->element_klass()->is_valuetype()) {
1063       // Do not bypass the klass load from the primary supertype array
1064       return NULL;
1065     }
1066   }
1067 
1068   // If 'superklass' has no subklasses and is not an interface, then we are
1069   // assured that the only input which will pass the type check is
1070   // 'superklass' itself.
1071   //
1072   // We could be more liberal here, and allow the optimization on interfaces
1073   // which have a single implementor.  This would require us to increase the
1074   // expressiveness of the add_dependency() mechanism.
1075   // %%% Do this after we fix TypeOopPtr:  Deps are expressive enough now.
1076 
1077   // Object arrays must have their base element have no subtypes
1078   while (superklass->is_obj_array_klass()) {
1079     ciType* elem = superklass->as_obj_array_klass()->element_type();
1080     superklass = elem->as_klass();
1081   }
1082   if (superklass->is_instance_klass()) {
1083     ciInstanceKlass* ik = superklass->as_instance_klass();
1084     if (ik->has_subklass() || ik->is_interface())  return NULL;
1085     // Add a dependency if there is a chance that a subclass will be added later.
1086     if (!ik->is_final()) {


< prev index next >