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




1184   Node* cmp = new CmpINode(test_value, phase->intcon(0));
1185   cmp = phase->transform(cmp);
1186   Node* bol = new BoolNode(cmp, BoolTest::ne);
1187   return phase->transform(bol);
1188 }
1189 
1190 //--------------------------------as_int_value---------------------------------
1191 Node* BoolNode::as_int_value(PhaseGVN* phase) {
1192   // Inverse to make_predicate.  The CMove probably boils down to a Conv2B.
1193   Node* cmov = CMoveNode::make(NULL, this,
1194                                phase->intcon(0), phase->intcon(1),
1195                                TypeInt::BOOL);
1196   return phase->transform(cmov);
1197 }
1198 
1199 //----------------------------------negate-------------------------------------
1200 BoolNode* BoolNode::negate(PhaseGVN* phase) {
1201   return new BoolNode(in(1), _test.negate());
1202 }
1203 
















































1204 
1205 //------------------------------Ideal------------------------------------------
1206 Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1207   // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)".
1208   // This moves the constant to the right.  Helps value-numbering.
1209   Node *cmp = in(1);
1210   if( !cmp->is_Sub() ) return NULL;
1211   int cop = cmp->Opcode();
1212   if( cop == Op_FastLock || cop == Op_FastUnlock) return NULL;
1213   Node *cmp1 = cmp->in(1);
1214   Node *cmp2 = cmp->in(2);
1215   if( !cmp1 ) return NULL;
1216 
1217   if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) {
1218     return NULL;
1219   }
1220 
1221   // Constant on left?
1222   Node *con = cmp1;
1223   uint op2 = cmp2->Opcode();


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



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


1321   //    // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an
1322   //    // exception in case X is 0 (because 0-1 turns into 4billion unsigned but
1323   //    // "0 <=u Y" is always true).
1324   //    if( cmp->Opcode() == Op_CmpU ) return NULL;
1325   //    int cmp2_op = cmp2->Opcode();
1326   //    if( _test._test == BoolTest::le ) {
1327   //      if( cmp1_op == Op_AddI &&
1328   //          phase->type( cmp1->in(2) ) == TypeInt::ONE )
1329   //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
1330   //      else if( cmp2_op == Op_AddI &&
1331   //         phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
1332   //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
1333   //    } else if( _test._test == BoolTest::lt ) {
1334   //      if( cmp1_op == Op_AddI &&
1335   //          phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
1336   //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
1337   //      else if( cmp2_op == Op_AddI &&
1338   //         phase->type( cmp2->in(2) ) == TypeInt::ONE )
1339   //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
1340   //    }
1341 
1342   return NULL;
1343 }
1344 
1345 //------------------------------Value------------------------------------------
1346 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
1347 // based on local information.   If the input is constant, do it.
1348 const Type *BoolNode::Value( PhaseTransform *phase ) const {
1349   return _test.cc2logical( phase->type( in(1) ) );
1350 }
1351 
1352 //------------------------------dump_spec--------------------------------------
1353 // Dump special per-node info
1354 #ifndef PRODUCT
1355 void BoolNode::dump_spec(outputStream *st) const {
1356   st->print("[");
1357   _test.dump_on(st);
1358   st->print("]");
1359 }
1360 #endif
1361 
1362 //------------------------------is_counted_loop_exit_test--------------------------------------




1184   Node* cmp = new CmpINode(test_value, phase->intcon(0));
1185   cmp = phase->transform(cmp);
1186   Node* bol = new BoolNode(cmp, BoolTest::ne);
1187   return phase->transform(bol);
1188 }
1189 
1190 //--------------------------------as_int_value---------------------------------
1191 Node* BoolNode::as_int_value(PhaseGVN* phase) {
1192   // Inverse to make_predicate.  The CMove probably boils down to a Conv2B.
1193   Node* cmov = CMoveNode::make(NULL, this,
1194                                phase->intcon(0), phase->intcon(1),
1195                                TypeInt::BOOL);
1196   return phase->transform(cmov);
1197 }
1198 
1199 //----------------------------------negate-------------------------------------
1200 BoolNode* BoolNode::negate(PhaseGVN* phase) {
1201   return new BoolNode(in(1), _test.negate());
1202 }
1203 
1204 // Change "bool eq/ne (cmp (add/sub A B) C)" into false/true if add/sub
1205 // overflows and we can prove that C is not in the two resulting ranges.
1206 // This optimization is similar to the one performed by CmpUNode::Value().
1207 Node* BoolNode::fold_cmpI(PhaseGVN* phase, SubNode* cmp, Node* cmp1, int cmp_op,
1208                           int cmp1_op, const TypeInt* cmp2_type) {
1209   // Only optimize eq/ne integer comparison of add/sub
1210   if((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1211      (cmp_op == Op_CmpI) && (cmp1_op == Op_AddI || cmp1_op == Op_SubI)) {
1212     // Skip cases were inputs of add/sub are not integers or of bottom type
1213     const TypeInt* r0 = phase->type(cmp1->in(1))->isa_int();
1214     const TypeInt* r1 = phase->type(cmp1->in(2))->isa_int();
1215     if ((r0 != NULL) && (r0 != TypeInt::INT) &&
1216         (r1 != NULL) && (r1 != TypeInt::INT) &&
1217         (cmp2_type != TypeInt::INT)) {
1218       // Compute exact (long) type range of add/sub result
1219       jlong lo_long = r0->_lo;
1220       jlong hi_long = r0->_hi;
1221       if (cmp1_op == Op_AddI) {
1222         lo_long += r1->_lo;
1223         hi_long += r1->_hi;
1224       } else {
1225         lo_long -= r1->_hi;
1226         hi_long -= r1->_lo;
1227       }
1228       // Check for over-/underflow by casting to integer
1229       int lo_int = (int)lo_long;
1230       int hi_int = (int)hi_long;
1231       bool underflow = lo_long != (jlong)lo_int;
1232       bool overflow  = hi_long != (jlong)hi_int;
1233       if ((underflow != overflow) && (hi_int < lo_int)) {
1234         // Overflow on one boundary, compute resulting type ranges:
1235         // tr1 [MIN_INT, hi_int] and tr2 [lo_int, MAX_INT]
1236         int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here
1237         const TypeInt* tr1 = TypeInt::make(min_jint, hi_int, w);
1238         const TypeInt* tr2 = TypeInt::make(lo_int, max_jint, w);
1239         // Compare second input of cmp to both type ranges
1240         const Type* sub_tr1 = cmp->sub(tr1, cmp2_type);
1241         const Type* sub_tr2 = cmp->sub(tr2, cmp2_type);
1242         if (sub_tr1 == TypeInt::CC_LT && sub_tr2 == TypeInt::CC_GT) {
1243           // The result of the add/sub will never equal cmp2. Replace BoolNode
1244           // by false (0) if it tests for equality and by true (1) otherwise.
1245           return ConINode::make((_test._test == BoolTest::eq) ? 0 : 1);
1246         }
1247       }
1248     }
1249   }
1250   return NULL;
1251 }
1252 
1253 //------------------------------Ideal------------------------------------------
1254 Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1255   // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)".
1256   // This moves the constant to the right.  Helps value-numbering.
1257   Node *cmp = in(1);
1258   if( !cmp->is_Sub() ) return NULL;
1259   int cop = cmp->Opcode();
1260   if( cop == Op_FastLock || cop == Op_FastUnlock) return NULL;
1261   Node *cmp1 = cmp->in(1);
1262   Node *cmp2 = cmp->in(2);
1263   if( !cmp1 ) return NULL;
1264 
1265   if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) {
1266     return NULL;
1267   }
1268 
1269   // Constant on left?
1270   Node *con = cmp1;
1271   uint op2 = cmp2->Opcode();


1325   if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1326         (cop == Op_CmpI) &&
1327         (cmp1->Opcode() == Op_SubI) &&
1328         ( cmp2_type == TypeInt::ZERO ) ) {
1329     Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),cmp1->in(2)));
1330     return new BoolNode( ncmp, _test._test );
1331   }
1332 
1333   // Change (-A vs 0) into (A vs 0) by commuting the test.  Disallow in the
1334   // most general case because negating 0x80000000 does nothing.  Needed for
1335   // the CmpF3/SubI/CmpI idiom.
1336   if( cop == Op_CmpI &&
1337       cmp1->Opcode() == Op_SubI &&
1338       cmp2_type == TypeInt::ZERO &&
1339       phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
1340       phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
1341     Node *ncmp = phase->transform( new CmpINode(cmp1->in(2),cmp2));
1342     return new BoolNode( ncmp, _test.commute() );
1343   }
1344 
1345   // Try to optimize signed integer comparison
1346   return fold_cmpI(phase, cmp->as_Sub(), cmp1, cop, cmp1_op, cmp2_type);
1347 
1348   //  The transformation below is not valid for either signed or unsigned
1349   //  comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE.
1350   //  This transformation can be resurrected when we are able to
1351   //  make inferences about the range of values being subtracted from
1352   //  (or added to) relative to the wraparound point.
1353   //
1354   //    // Remove +/-1's if possible.
1355   //    // "X <= Y-1" becomes "X <  Y"
1356   //    // "X+1 <= Y" becomes "X <  Y"
1357   //    // "X <  Y+1" becomes "X <= Y"
1358   //    // "X-1 <  Y" becomes "X <= Y"
1359   //    // Do not this to compares off of the counted-loop-end.  These guys are
1360   //    // checking the trip counter and they want to use the post-incremented
1361   //    // counter.  If they use the PRE-incremented counter, then the counter has
1362   //    // to be incremented in a private block on a loop backedge.
1363   //    if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd )
1364   //      return NULL;
1365   //  #ifndef PRODUCT
1366   //    // Do not do this in a wash GVN pass during verification.
1367   //    // Gets triggered by too many simple optimizations to be bothered with


1372   //    // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an
1373   //    // exception in case X is 0 (because 0-1 turns into 4billion unsigned but
1374   //    // "0 <=u Y" is always true).
1375   //    if( cmp->Opcode() == Op_CmpU ) return NULL;
1376   //    int cmp2_op = cmp2->Opcode();
1377   //    if( _test._test == BoolTest::le ) {
1378   //      if( cmp1_op == Op_AddI &&
1379   //          phase->type( cmp1->in(2) ) == TypeInt::ONE )
1380   //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
1381   //      else if( cmp2_op == Op_AddI &&
1382   //         phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
1383   //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
1384   //    } else if( _test._test == BoolTest::lt ) {
1385   //      if( cmp1_op == Op_AddI &&
1386   //          phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
1387   //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
1388   //      else if( cmp2_op == Op_AddI &&
1389   //         phase->type( cmp2->in(2) ) == TypeInt::ONE )
1390   //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
1391   //    }


1392 }
1393 
1394 //------------------------------Value------------------------------------------
1395 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
1396 // based on local information.   If the input is constant, do it.
1397 const Type *BoolNode::Value( PhaseTransform *phase ) const {
1398   return _test.cc2logical( phase->type( in(1) ) );
1399 }
1400 
1401 //------------------------------dump_spec--------------------------------------
1402 // Dump special per-node info
1403 #ifndef PRODUCT
1404 void BoolNode::dump_spec(outputStream *st) const {
1405   st->print("[");
1406   _test.dump_on(st);
1407   st->print("]");
1408 }
1409 #endif
1410 
1411 //------------------------------is_counted_loop_exit_test--------------------------------------


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