< prev index next >

src/share/vm/opto/convertnode.cpp

Print this page




 277             // Keep a range assertion of >=0.
 278             lo1 = 0;        hi1 = max_jint;
 279           } else if (hi1 < 0) {
 280             // Keep a range assertion of <0.
 281             lo1 = min_jint; hi1 = -1;
 282           } else {
 283             lo1 = min_jint; hi1 = max_jint;
 284           }
 285           const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
 286                                                  MIN2((jlong)in_type->_hi, hi1),
 287                                                  MAX2((int)in_type->_widen, w1));
 288           if (wtype != type()) {
 289             set_type(wtype);
 290             // Note: this_type still has old type value, for the logic below.
 291             this_changed = this;
 292           }
 293         }
 294   }
 295 
 296 #ifdef _LP64
 297   // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) or
 298   // ConvI2L(CastII(AddI(x, y))) to AddL(ConvI2L(CastII(x)), ConvI2L(CastII(y))),
 299   // but only if x and y have subranges that cannot cause 32-bit overflow,
 300   // under the assumption that x+y is in my own subrange this->type().
 301 
 302   // This assumption is based on a constraint (i.e., type assertion)
 303   // established in Parse::array_addressing or perhaps elsewhere.
 304   // This constraint has been adjoined to the "natural" type of
 305   // the incoming argument in(0).  We know (because of runtime
 306   // checks) - that the result value I2L(x+y) is in the joined range.
 307   // Hence we can restrict the incoming terms (x, y) to values such
 308   // that their sum also lands in that range.
 309 
 310   // This optimization is useful only on 64-bit systems, where we hope
 311   // the addition will end up subsumed in an addressing mode.
 312   // It is necessary to do this when optimizing an unrolled array
 313   // copy loop such as x[i++] = y[i++].
 314 
 315   // On 32-bit systems, it's better to perform as much 32-bit math as
 316   // possible before the I2L conversion, because 32-bit math is cheaper.
 317   // There's no common reason to "leak" a constant offset through the I2L.
 318   // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
 319 
 320   Node* z = in(1);
 321   int op = z->Opcode();
 322   Node* ctrl = NULL;
 323   if (op == Op_CastII && z->as_CastII()->has_range_check()) {
 324     // Skip CastII node but save control dependency
 325     ctrl = z->in(0);
 326     z = z->in(1);
 327     op = z->Opcode();
 328   }
 329   if (op == Op_AddI || op == Op_SubI) {
 330     Node* x = z->in(1);
 331     Node* y = z->in(2);
 332     assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
 333     if (phase->type(x) == Type::TOP)  return this_changed;
 334     if (phase->type(y) == Type::TOP)  return this_changed;
 335     const TypeInt*  tx = phase->type(x)->is_int();
 336     const TypeInt*  ty = phase->type(y)->is_int();
 337     const TypeLong* tz = this_type;
 338     jlong xlo = tx->_lo;
 339     jlong xhi = tx->_hi;
 340     jlong ylo = ty->_lo;
 341     jlong yhi = ty->_hi;
 342     jlong zlo = tz->_lo;
 343     jlong zhi = tz->_hi;
 344     jlong vbit = CONST64(1) << BitsPerInt;
 345     int widen =  MAX2(tx->_widen, ty->_widen);
 346     if (op == Op_SubI) {
 347       jlong ylo0 = ylo;
 348       ylo = -yhi;


 368     // of the I2L conversion.  Here's the interval arithmetic algebra:
 369     //    x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
 370     //    => x in [zlo-yhi, zhi-ylo]
 371     //    => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
 372     //    => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
 373     jlong rxlo = MAX2(xlo, zlo - yhi);
 374     jlong rxhi = MIN2(xhi, zhi - ylo);
 375     // And similarly, x changing place with y:
 376     jlong rylo = MAX2(ylo, zlo - xhi);
 377     jlong ryhi = MIN2(yhi, zhi - xlo);
 378     if (rxlo > rxhi || rylo > ryhi) {
 379       return this_changed;  // x or y is dying; don't mess w/ it
 380     }
 381     if (op == Op_SubI) {
 382       jlong rylo0 = rylo;
 383       rylo = -ryhi;
 384       ryhi = -rylo0;
 385     }
 386     assert(rxlo == (int)rxlo && rxhi == (int)rxhi, "x should not overflow");
 387     assert(rylo == (int)rylo && ryhi == (int)ryhi, "y should not overflow");
 388     Node* cx = phase->C->constrained_convI2L(phase, x, TypeInt::make(rxlo, rxhi, widen), ctrl);
 389     Node* cy = phase->C->constrained_convI2L(phase, y, TypeInt::make(rylo, ryhi, widen), ctrl);
 390     switch (op) {
 391       case Op_AddI:  return new AddLNode(cx, cy);
 392       case Op_SubI:  return new SubLNode(cx, cy);
 393       default:       ShouldNotReachHere();
 394     }
 395   }
 396 #endif //_LP64
 397 
 398   return this_changed;
 399 }
 400 
 401 //=============================================================================
 402 //------------------------------Value------------------------------------------
 403 const Type* ConvL2DNode::Value(PhaseGVN* phase) const {
 404   const Type *t = phase->type( in(1) );
 405   if( t == Type::TOP ) return Type::TOP;
 406   const TypeLong *tl = t->is_long();
 407   if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
 408   return bottom_type();
 409 }




 277             // Keep a range assertion of >=0.
 278             lo1 = 0;        hi1 = max_jint;
 279           } else if (hi1 < 0) {
 280             // Keep a range assertion of <0.
 281             lo1 = min_jint; hi1 = -1;
 282           } else {
 283             lo1 = min_jint; hi1 = max_jint;
 284           }
 285           const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
 286                                                  MIN2((jlong)in_type->_hi, hi1),
 287                                                  MAX2((int)in_type->_widen, w1));
 288           if (wtype != type()) {
 289             set_type(wtype);
 290             // Note: this_type still has old type value, for the logic below.
 291             this_changed = this;
 292           }
 293         }
 294   }
 295 
 296 #ifdef _LP64
 297   // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y))

 298   // but only if x and y have subranges that cannot cause 32-bit overflow,
 299   // under the assumption that x+y is in my own subrange this->type().
 300 
 301   // This assumption is based on a constraint (i.e., type assertion)
 302   // established in Parse::array_addressing or perhaps elsewhere.
 303   // This constraint has been adjoined to the "natural" type of
 304   // the incoming argument in(0).  We know (because of runtime
 305   // checks) - that the result value I2L(x+y) is in the joined range.
 306   // Hence we can restrict the incoming terms (x, y) to values such
 307   // that their sum also lands in that range.
 308 
 309   // This optimization is useful only on 64-bit systems, where we hope
 310   // the addition will end up subsumed in an addressing mode.
 311   // It is necessary to do this when optimizing an unrolled array
 312   // copy loop such as x[i++] = y[i++].
 313 
 314   // On 32-bit systems, it's better to perform as much 32-bit math as
 315   // possible before the I2L conversion, because 32-bit math is cheaper.
 316   // There's no common reason to "leak" a constant offset through the I2L.
 317   // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
 318 
 319   Node* z = in(1);
 320   int op = z->Opcode();







 321   if (op == Op_AddI || op == Op_SubI) {
 322     Node* x = z->in(1);
 323     Node* y = z->in(2);
 324     assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
 325     if (phase->type(x) == Type::TOP)  return this_changed;
 326     if (phase->type(y) == Type::TOP)  return this_changed;
 327     const TypeInt*  tx = phase->type(x)->is_int();
 328     const TypeInt*  ty = phase->type(y)->is_int();
 329     const TypeLong* tz = this_type;
 330     jlong xlo = tx->_lo;
 331     jlong xhi = tx->_hi;
 332     jlong ylo = ty->_lo;
 333     jlong yhi = ty->_hi;
 334     jlong zlo = tz->_lo;
 335     jlong zhi = tz->_hi;
 336     jlong vbit = CONST64(1) << BitsPerInt;
 337     int widen =  MAX2(tx->_widen, ty->_widen);
 338     if (op == Op_SubI) {
 339       jlong ylo0 = ylo;
 340       ylo = -yhi;


 360     // of the I2L conversion.  Here's the interval arithmetic algebra:
 361     //    x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
 362     //    => x in [zlo-yhi, zhi-ylo]
 363     //    => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
 364     //    => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
 365     jlong rxlo = MAX2(xlo, zlo - yhi);
 366     jlong rxhi = MIN2(xhi, zhi - ylo);
 367     // And similarly, x changing place with y:
 368     jlong rylo = MAX2(ylo, zlo - xhi);
 369     jlong ryhi = MIN2(yhi, zhi - xlo);
 370     if (rxlo > rxhi || rylo > ryhi) {
 371       return this_changed;  // x or y is dying; don't mess w/ it
 372     }
 373     if (op == Op_SubI) {
 374       jlong rylo0 = rylo;
 375       rylo = -ryhi;
 376       ryhi = -rylo0;
 377     }
 378     assert(rxlo == (int)rxlo && rxhi == (int)rxhi, "x should not overflow");
 379     assert(rylo == (int)rylo && ryhi == (int)ryhi, "y should not overflow");
 380     Node* cx = phase->C->constrained_convI2L(phase, x, TypeInt::make(rxlo, rxhi, widen), NULL);
 381     Node* cy = phase->C->constrained_convI2L(phase, y, TypeInt::make(rylo, ryhi, widen), NULL);
 382     switch (op) {
 383       case Op_AddI:  return new AddLNode(cx, cy);
 384       case Op_SubI:  return new SubLNode(cx, cy);
 385       default:       ShouldNotReachHere();
 386     }
 387   }
 388 #endif //_LP64
 389 
 390   return this_changed;
 391 }
 392 
 393 //=============================================================================
 394 //------------------------------Value------------------------------------------
 395 const Type* ConvL2DNode::Value(PhaseGVN* phase) const {
 396   const Type *t = phase->type( in(1) );
 397   if( t == Type::TOP ) return Type::TOP;
 398   const TypeLong *tl = t->is_long();
 399   if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
 400   return bottom_type();
 401 }


< prev index next >