hotspot/src/share/vm/opto/castnode.cpp
changeset 35549 3415401a6b6e
parent 35545 a8f29dfd62b2
child 35551 36ef3841fb34
equal deleted inserted replaced
35547:0ee84aa8e705 35549:3415401a6b6e
   213     }
   213     }
   214   }
   214   }
   215   return res;
   215   return res;
   216 }
   216 }
   217 
   217 
       
   218 Node *CastIINode::Ideal(PhaseGVN *phase, bool can_reshape) {
       
   219   Node* progress = ConstraintCastNode::Ideal(phase, can_reshape);
       
   220   if (progress != NULL) {
       
   221     return progress;
       
   222   }
       
   223 
       
   224   // transform:
       
   225   // (CastII (AddI x const)) -> (AddI (CastII x) const)
       
   226   // So the AddI has a chance to be optimized out
       
   227   if (in(1)->Opcode() == Op_AddI) {
       
   228     Node* in2 = in(1)->in(2);
       
   229     const TypeInt* in2_t = phase->type(in2)->isa_int();
       
   230     if (in2_t != NULL && in2_t->singleton()) {
       
   231       int in2_const = in2_t->_lo;
       
   232       const TypeInt* current_type = _type->is_int();
       
   233       jlong new_lo_long = ((jlong)current_type->_lo) - in2_const;
       
   234       jlong new_hi_long = ((jlong)current_type->_hi) - in2_const;
       
   235       int new_lo = (int)new_lo_long;
       
   236       int new_hi = (int)new_hi_long;
       
   237       if (((jlong)new_lo) == new_lo_long && ((jlong)new_hi) == new_hi_long) {
       
   238         Node* in1 = in(1)->in(1);
       
   239         CastIINode* new_cast = (CastIINode*)clone();
       
   240         AddINode* new_add = (AddINode*)in(1)->clone();
       
   241         new_cast->set_type(TypeInt::make(new_lo, new_hi, current_type->_widen));
       
   242         new_cast->set_req(1, in1);
       
   243         new_add->set_req(1, phase->transform(new_cast));
       
   244         return new_add;
       
   245       }
       
   246     }
       
   247   }
       
   248   // Similar to ConvI2LNode::Ideal() for the same reasons
       
   249   if (can_reshape && !phase->C->major_progress()) {
       
   250     const TypeInt* this_type = this->type()->is_int();
       
   251     const TypeInt* in_type = phase->type(in(1))->isa_int();
       
   252     if (in_type != NULL && this_type != NULL &&
       
   253         (in_type->_lo != this_type->_lo ||
       
   254          in_type->_hi != this_type->_hi)) {
       
   255       int lo1 = this_type->_lo;
       
   256       int hi1 = this_type->_hi;
       
   257       int w1  = this_type->_widen;
       
   258 
       
   259       if (lo1 >= 0) {
       
   260         // Keep a range assertion of >=0.
       
   261         lo1 = 0;        hi1 = max_jint;
       
   262       } else if (hi1 < 0) {
       
   263         // Keep a range assertion of <0.
       
   264         lo1 = min_jint; hi1 = -1;
       
   265       } else {
       
   266         lo1 = min_jint; hi1 = max_jint;
       
   267       }
       
   268       const TypeInt* wtype = TypeInt::make(MAX2(in_type->_lo, lo1),
       
   269                                            MIN2(in_type->_hi, hi1),
       
   270                                            MAX2((int)in_type->_widen, w1));
       
   271       if (wtype != type()) {
       
   272         set_type(wtype);
       
   273         return this;
       
   274       }
       
   275     }
       
   276   }
       
   277   return NULL;
       
   278 }
       
   279 
   218 //=============================================================================
   280 //=============================================================================
   219 //------------------------------Identity---------------------------------------
   281 //------------------------------Identity---------------------------------------
   220 // If input is already higher or equal to cast type, then this is an identity.
   282 // If input is already higher or equal to cast type, then this is an identity.
   221 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
   283 Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
   222   Node* dom = dominating_cast(phase);
   284   Node* dom = dominating_cast(phase);