src/share/vm/opto/subnode.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8043284 Sdiff src/share/vm/opto

src/share/vm/opto/subnode.cpp

Print this page




1279   if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1280         (cop == Op_CmpI) &&
1281         (cmp1->Opcode() == Op_SubI) &&
1282         ( cmp2_type == TypeInt::ZERO ) ) {
1283     Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),cmp1->in(2)));
1284     return new BoolNode( ncmp, _test._test );
1285   }
1286 
1287   // Change (-A vs 0) into (A vs 0) by commuting the test.  Disallow in the
1288   // most general case because negating 0x80000000 does nothing.  Needed for
1289   // the CmpF3/SubI/CmpI idiom.
1290   if( cop == Op_CmpI &&
1291       cmp1->Opcode() == Op_SubI &&
1292       cmp2_type == TypeInt::ZERO &&
1293       phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
1294       phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
1295     Node *ncmp = phase->transform( new CmpINode(cmp1->in(2),cmp2));
1296     return new BoolNode( ncmp, _test.commute() );
1297   }
1298 













































1299   //  The transformation below is not valid for either signed or unsigned
1300   //  comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE.
1301   //  This transformation can be resurrected when we are able to
1302   //  make inferences about the range of values being subtracted from
1303   //  (or added to) relative to the wraparound point.
1304   //
1305   //    // Remove +/-1's if possible.
1306   //    // "X <= Y-1" becomes "X <  Y"
1307   //    // "X+1 <= Y" becomes "X <  Y"
1308   //    // "X <  Y+1" becomes "X <= Y"
1309   //    // "X-1 <  Y" becomes "X <= Y"
1310   //    // Do not this to compares off of the counted-loop-end.  These guys are
1311   //    // checking the trip counter and they want to use the post-incremented
1312   //    // counter.  If they use the PRE-incremented counter, then the counter has
1313   //    // to be incremented in a private block on a loop backedge.
1314   //    if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd )
1315   //      return NULL;
1316   //  #ifndef PRODUCT
1317   //    // Do not do this in a wash GVN pass during verification.
1318   //    // Gets triggered by too many simple optimizations to be bothered with




1279   if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1280         (cop == Op_CmpI) &&
1281         (cmp1->Opcode() == Op_SubI) &&
1282         ( cmp2_type == TypeInt::ZERO ) ) {
1283     Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),cmp1->in(2)));
1284     return new BoolNode( ncmp, _test._test );
1285   }
1286 
1287   // Change (-A vs 0) into (A vs 0) by commuting the test.  Disallow in the
1288   // most general case because negating 0x80000000 does nothing.  Needed for
1289   // the CmpF3/SubI/CmpI idiom.
1290   if( cop == Op_CmpI &&
1291       cmp1->Opcode() == Op_SubI &&
1292       cmp2_type == TypeInt::ZERO &&
1293       phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
1294       phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
1295     Node *ncmp = phase->transform( new CmpINode(cmp1->in(2),cmp2));
1296     return new BoolNode( ncmp, _test.commute() );
1297   }
1298 
1299   // Change "bool eq/ne (cmp (add/sub A B) C)" into false/true if add/sub
1300   // overflows and we can prove that C is not in the two resulting ranges.
1301   // This optimization is similar to the one performed by CmpUNode::Value().
1302   if((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1303      (cop == Op_CmpI) && (cmp1_op == Op_AddI || cmp1_op == Op_SubI)) {
1304     // Skip cases were inputs of add/sub are not integers or of bottom type
1305     const TypeInt* r0 = phase->type(cmp1->in(1))->isa_int();
1306     const TypeInt* r1 = phase->type(cmp1->in(2))->isa_int();
1307     if ((r0 != NULL) && (r0 != TypeInt::INT) &&
1308         (r1 != NULL) && (r1 != TypeInt::INT) &&
1309         (cmp2_type != TypeInt::INT)) {
1310       // Compute exact (long) type range of add/sub result
1311       jlong lo_long = r0->_lo;
1312       jlong hi_long = r0->_hi;
1313       if (cmp1_op == Op_AddI) {
1314         lo_long += r1->_lo;
1315         hi_long += r1->_hi;
1316       } else {
1317         lo_long -= r1->_hi;
1318         hi_long -= r1->_lo;
1319       }
1320       // Check for over-/underflow by casting to integer
1321       int lo_int = (int)lo_long;
1322       int hi_int = (int)hi_long;
1323       bool underflow = lo_long != (jlong)lo_int;
1324       bool overflow  = hi_long != (jlong)hi_int;
1325       if ((underflow != overflow) && (hi_int < lo_int)) {
1326         // Overflow on one boundary, compute resulting type ranges:
1327         // tr1 [MIN_INT, hi_int] and tr2 [lo_int, MAX_INT]
1328         int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here
1329         const TypeInt* tr1 = TypeInt::make(min_jint, hi_int, w);
1330         const TypeInt* tr2 = TypeInt::make(lo_int, max_jint, w);
1331         // Compare second input of cmp to both type ranges
1332         const Type* sub_tr1 = cmp->as_Sub()->sub(tr1, cmp2_type);
1333         const Type* sub_tr2 = cmp->as_Sub()->sub(tr2, cmp2_type);
1334         if ((sub_tr1 == TypeInt::CC_LT && sub_tr2 == TypeInt::CC_GT) ||
1335             (sub_tr1 == TypeInt::CC_GT && sub_tr2 == TypeInt::CC_LT)) {
1336           // The result of the add/sub will never equal cmp2. Replace BoolNode
1337           // by false (0) if it tests for equality and by true (1) otherwise.
1338           return ConINode::make(phase->C, (_test._test == BoolTest::eq) ? 0 : 1);
1339         }
1340       }
1341     }
1342   }
1343 
1344   //  The transformation below is not valid for either signed or unsigned
1345   //  comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE.
1346   //  This transformation can be resurrected when we are able to
1347   //  make inferences about the range of values being subtracted from
1348   //  (or added to) relative to the wraparound point.
1349   //
1350   //    // Remove +/-1's if possible.
1351   //    // "X <= Y-1" becomes "X <  Y"
1352   //    // "X+1 <= Y" becomes "X <  Y"
1353   //    // "X <  Y+1" becomes "X <= Y"
1354   //    // "X-1 <  Y" becomes "X <= Y"
1355   //    // Do not this to compares off of the counted-loop-end.  These guys are
1356   //    // checking the trip counter and they want to use the post-incremented
1357   //    // counter.  If they use the PRE-incremented counter, then the counter has
1358   //    // to be incremented in a private block on a loop backedge.
1359   //    if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd )
1360   //      return NULL;
1361   //  #ifndef PRODUCT
1362   //    // Do not do this in a wash GVN pass during verification.
1363   //    // Gets triggered by too many simple optimizations to be bothered with


src/share/vm/opto/subnode.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File