src/hotspot/share/opto/subnode.cpp
changeset 58104 46e11f978852
parent 54701 6b77693eda6a
equal deleted inserted replaced
58103:689a80d20550 58104:46e11f978852
   817     // Equal pointer constants (klasses, nulls, etc.)
   817     // Equal pointer constants (klasses, nulls, etc.)
   818     return TypeInt::CC_EQ;
   818     return TypeInt::CC_EQ;
   819   }
   819   }
   820 
   820 
   821   // See if it is 2 unrelated classes.
   821   // See if it is 2 unrelated classes.
   822   const TypeOopPtr* p0 = r0->isa_oopptr();
   822   const TypeOopPtr* oop_p0 = r0->isa_oopptr();
   823   const TypeOopPtr* p1 = r1->isa_oopptr();
   823   const TypeOopPtr* oop_p1 = r1->isa_oopptr();
   824   if (p0 && p1) {
   824   bool both_oop_ptr = oop_p0 && oop_p1;
       
   825 
       
   826   if (both_oop_ptr) {
   825     Node* in1 = in(1)->uncast();
   827     Node* in1 = in(1)->uncast();
   826     Node* in2 = in(2)->uncast();
   828     Node* in2 = in(2)->uncast();
   827     AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL);
   829     AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL);
   828     AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL);
   830     AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL);
   829     if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
   831     if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
   830       return TypeInt::CC_GT;  // different pointers
   832       return TypeInt::CC_GT;  // different pointers
   831     }
   833     }
   832     ciKlass* klass0 = p0->klass();
   834   }
   833     bool    xklass0 = p0->klass_is_exact();
   835 
   834     ciKlass* klass1 = p1->klass();
   836   const TypeKlassPtr* klass_p0 = r0->isa_klassptr();
   835     bool    xklass1 = p1->klass_is_exact();
   837   const TypeKlassPtr* klass_p1 = r1->isa_klassptr();
   836     int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
   838 
       
   839   if (both_oop_ptr || (klass_p0 && klass_p1)) { // both or neither are klass pointers
       
   840     ciKlass* klass0 = NULL;
       
   841     bool    xklass0 = false;
       
   842     ciKlass* klass1 = NULL;
       
   843     bool    xklass1 = false;
       
   844 
       
   845     if (oop_p0) {
       
   846       klass0 = oop_p0->klass();
       
   847       xklass0 = oop_p0->klass_is_exact();
       
   848     } else {
       
   849       assert(klass_p0, "must be non-null if oop_p0 is null");
       
   850       klass0 = klass_p0->klass();
       
   851       xklass0 = klass_p0->klass_is_exact();
       
   852     }
       
   853 
       
   854     if (oop_p1) {
       
   855       klass1 = oop_p1->klass();
       
   856       xklass1 = oop_p1->klass_is_exact();
       
   857     } else {
       
   858       assert(klass_p1, "must be non-null if oop_p1 is null");
       
   859       klass1 = klass_p1->klass();
       
   860       xklass1 = klass_p1->klass_is_exact();
       
   861     }
       
   862 
   837     if (klass0 && klass1 &&
   863     if (klass0 && klass1 &&
   838         kps != 1 &&             // both or neither are klass pointers
       
   839         klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces
   864         klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces
   840         klass1->is_loaded() && !klass1->is_interface() &&
   865         klass1->is_loaded() && !klass1->is_interface() &&
   841         (!klass0->is_obj_array_klass() ||
   866         (!klass0->is_obj_array_klass() ||
   842          !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) &&
   867          !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) &&
   843         (!klass1->is_obj_array_klass() ||
   868         (!klass1->is_obj_array_klass() ||
  1052 //=============================================================================
  1077 //=============================================================================
  1053 //------------------------------sub--------------------------------------------
  1078 //------------------------------sub--------------------------------------------
  1054 // Simplify an CmpN (compare 2 pointers) node, based on local information.
  1079 // Simplify an CmpN (compare 2 pointers) node, based on local information.
  1055 // If both inputs are constants, compare them.
  1080 // If both inputs are constants, compare them.
  1056 const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const {
  1081 const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const {
  1057   const TypePtr *r0 = t1->make_ptr(); // Handy access
  1082   ShouldNotReachHere();
  1058   const TypePtr *r1 = t2->make_ptr();
  1083   return bottom_type();
  1059 
       
  1060   // Undefined inputs makes for an undefined result
       
  1061   if ((r0 == NULL) || (r1 == NULL) ||
       
  1062       TypePtr::above_centerline(r0->_ptr) ||
       
  1063       TypePtr::above_centerline(r1->_ptr)) {
       
  1064     return Type::TOP;
       
  1065   }
       
  1066   if (r0 == r1 && r0->singleton()) {
       
  1067     // Equal pointer constants (klasses, nulls, etc.)
       
  1068     return TypeInt::CC_EQ;
       
  1069   }
       
  1070 
       
  1071   // See if it is 2 unrelated classes.
       
  1072   const TypeOopPtr* p0 = r0->isa_oopptr();
       
  1073   const TypeOopPtr* p1 = r1->isa_oopptr();
       
  1074   if (p0 && p1) {
       
  1075     ciKlass* klass0 = p0->klass();
       
  1076     bool    xklass0 = p0->klass_is_exact();
       
  1077     ciKlass* klass1 = p1->klass();
       
  1078     bool    xklass1 = p1->klass_is_exact();
       
  1079     int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
       
  1080     if (klass0 && klass1 &&
       
  1081         kps != 1 &&             // both or neither are klass pointers
       
  1082         !klass0->is_interface() && // do not trust interfaces
       
  1083         !klass1->is_interface()) {
       
  1084       bool unrelated_classes = false;
       
  1085       // See if neither subclasses the other, or if the class on top
       
  1086       // is precise.  In either of these cases, the compare is known
       
  1087       // to fail if at least one of the pointers is provably not null.
       
  1088       if (klass0->equals(klass1)) { // if types are unequal but klasses are equal
       
  1089         // Do nothing; we know nothing for imprecise types
       
  1090       } else if (klass0->is_subtype_of(klass1)) {
       
  1091         // If klass1's type is PRECISE, then classes are unrelated.
       
  1092         unrelated_classes = xklass1;
       
  1093       } else if (klass1->is_subtype_of(klass0)) {
       
  1094         // If klass0's type is PRECISE, then classes are unrelated.
       
  1095         unrelated_classes = xklass0;
       
  1096       } else {                  // Neither subtypes the other
       
  1097         unrelated_classes = true;
       
  1098       }
       
  1099       if (unrelated_classes) {
       
  1100         // The oops classes are known to be unrelated. If the joined PTRs of
       
  1101         // two oops is not Null and not Bottom, then we are sure that one
       
  1102         // of the two oops is non-null, and the comparison will always fail.
       
  1103         TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
       
  1104         if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
       
  1105           return TypeInt::CC_GT;
       
  1106         }
       
  1107       }
       
  1108     }
       
  1109   }
       
  1110 
       
  1111   // Known constants can be compared exactly
       
  1112   // Null can be distinguished from any NotNull pointers
       
  1113   // Unknown inputs makes an unknown result
       
  1114   if( r0->singleton() ) {
       
  1115     intptr_t bits0 = r0->get_con();
       
  1116     if( r1->singleton() )
       
  1117       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
       
  1118     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
       
  1119   } else if( r1->singleton() ) {
       
  1120     intptr_t bits1 = r1->get_con();
       
  1121     return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
       
  1122   } else
       
  1123     return TypeInt::CC;
       
  1124 }
  1084 }
  1125 
  1085 
  1126 //------------------------------Ideal------------------------------------------
  1086 //------------------------------Ideal------------------------------------------
  1127 Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
  1087 Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
  1128   return NULL;
  1088   return NULL;