< prev index next >

src/share/vm/opto/convertnode.cpp

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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 "precompiled.hpp"
  26 #include "opto/addnode.hpp"

  27 #include "opto/convertnode.hpp"
  28 #include "opto/matcher.hpp"
  29 #include "opto/phaseX.hpp"
  30 #include "opto/subnode.hpp"
  31 #include "runtime/sharedRuntime.hpp"
  32 
  33 //=============================================================================
  34 //------------------------------Identity---------------------------------------
  35 Node* Conv2BNode::Identity(PhaseGVN* phase) {
  36   const Type *t = phase->type( in(1) );
  37   if( t == Type::TOP ) return in(1);
  38   if( t == TypeInt::ZERO ) return in(1);
  39   if( t == TypeInt::ONE ) return in(1);
  40   if( t == TypeInt::BOOL ) return in(1);
  41   return this;
  42 }
  43 
  44 //------------------------------Value------------------------------------------
  45 const Type* Conv2BNode::Value(PhaseGVN* phase) const {
  46   const Type *t = phase->type( in(1) );


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

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







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


 357     // more "restricted" range by intersecting [xlo,xhi] with the
 358     // range obtained by subtracting y's range from the asserted range
 359     // of the I2L conversion.  Here's the interval arithmetic algebra:
 360     //    x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
 361     //    => x in [zlo-yhi, zhi-ylo]
 362     //    => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
 363     //    => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
 364     jlong rxlo = MAX2(xlo, zlo - yhi);
 365     jlong rxhi = MIN2(xhi, zhi - ylo);
 366     // And similarly, x changing place with y:
 367     jlong rylo = MAX2(ylo, zlo - xhi);
 368     jlong ryhi = MIN2(yhi, zhi - xlo);
 369     if (rxlo > rxhi || rylo > ryhi) {
 370       return this_changed;  // x or y is dying; don't mess w/ it
 371     }
 372     if (op == Op_SubI) {
 373       jlong rylo0 = rylo;
 374       rylo = -ryhi;
 375       ryhi = -rylo0;
 376     }
 377 
 378     Node* cx = phase->transform( new ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) );
 379     Node* cy = phase->transform( new ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) );

 380     switch (op) {
 381       case Op_AddI:  return new AddLNode(cx, cy);
 382       case Op_SubI:  return new SubLNode(cx, cy);
 383       default:       ShouldNotReachHere();
 384     }
 385   }
 386 #endif //_LP64
 387 
 388   return this_changed;
 389 }
 390 
 391 //=============================================================================
 392 //------------------------------Value------------------------------------------
 393 const Type* ConvL2DNode::Value(PhaseGVN* phase) const {
 394   const Type *t = phase->type( in(1) );
 395   if( t == Type::TOP ) return Type::TOP;
 396   const TypeLong *tl = t->is_long();
 397   if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
 398   return bottom_type();
 399 }




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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 "precompiled.hpp"
  26 #include "opto/addnode.hpp"
  27 #include "opto/castnode.hpp"
  28 #include "opto/convertnode.hpp"
  29 #include "opto/matcher.hpp"
  30 #include "opto/phaseX.hpp"
  31 #include "opto/subnode.hpp"
  32 #include "runtime/sharedRuntime.hpp"
  33 
  34 //=============================================================================
  35 //------------------------------Identity---------------------------------------
  36 Node* Conv2BNode::Identity(PhaseGVN* phase) {
  37   const Type *t = phase->type( in(1) );
  38   if( t == Type::TOP ) return in(1);
  39   if( t == TypeInt::ZERO ) return in(1);
  40   if( t == TypeInt::ONE ) return in(1);
  41   if( t == TypeInt::BOOL ) return in(1);
  42   return this;
  43 }
  44 
  45 //------------------------------Value------------------------------------------
  46 const Type* Conv2BNode::Value(PhaseGVN* phase) const {
  47   const Type *t = phase->type( in(1) );


 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;


 366     // more "restricted" range by intersecting [xlo,xhi] with the
 367     // range obtained by subtracting y's range from the asserted range
 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 }


< prev index next >