@@ -1109,6 +1109,14 @@ void State::addInfoFor(BasicBlock &BB) {
1109
1109
CmpI->getOperand (1 )));
1110
1110
}
1111
1111
1112
+ static void dumpUnpackedICmp (raw_ostream &OS, ICmpInst::Predicate Pred,
1113
+ Value *LHS, Value *RHS) {
1114
+ OS << " icmp " << Pred << ' ' ;
1115
+ LHS->printAsOperand (OS, /* PrintType=*/ true );
1116
+ OS << " , " ;
1117
+ RHS->printAsOperand (OS, /* PrintType=*/ false );
1118
+ }
1119
+
1112
1120
namespace {
1113
1121
// / Helper to keep track of a condition and if it should be treated as negated
1114
1122
// / for reproducer construction.
@@ -1241,10 +1249,9 @@ static void generateReproducer(CmpInst *Cond, Module *M,
1241
1249
if (Entry.Pred == ICmpInst::BAD_ICMP_PREDICATE)
1242
1250
continue ;
1243
1251
1244
- LLVM_DEBUG (
1245
- dbgs () << " Materializing assumption icmp " << Entry.Pred << ' ' ;
1246
- Entry.LHS ->printAsOperand (dbgs (), /* PrintType=*/ true ); dbgs () << " , " ;
1247
- Entry.RHS ->printAsOperand (dbgs (), /* PrintType=*/ false ); dbgs () << " \n " );
1252
+ LLVM_DEBUG (dbgs () << " Materializing assumption " ;
1253
+ dumpUnpackedICmp (dbgs (), Entry.Pred , Entry.LHS , Entry.RHS );
1254
+ dbgs () << " \n " );
1248
1255
CloneInstructions ({Entry.LHS , Entry.RHS }, CmpInst::isSigned (Entry.Pred ));
1249
1256
1250
1257
auto *Cmp = Builder.CreateICmp (Entry.Pred , Entry.LHS , Entry.RHS );
@@ -1260,14 +1267,12 @@ static void generateReproducer(CmpInst *Cond, Module *M,
1260
1267
assert (!verifyFunction (*F, &dbgs ()));
1261
1268
}
1262
1269
1263
- static std::optional<bool > checkCondition (CmpInst *Cmp, ConstraintInfo &Info,
1264
- unsigned NumIn, unsigned NumOut,
1270
+ static std::optional<bool > checkCondition (CmpInst::Predicate Pred, Value *A,
1271
+ Value *B, Instruction *CheckInst,
1272
+ ConstraintInfo &Info, unsigned NumIn,
1273
+ unsigned NumOut,
1265
1274
Instruction *ContextInst) {
1266
- LLVM_DEBUG (dbgs () << " Checking " << *Cmp << " \n " );
1267
-
1268
- CmpInst::Predicate Pred = Cmp->getPredicate ();
1269
- Value *A = Cmp->getOperand (0 );
1270
- Value *B = Cmp->getOperand (1 );
1275
+ LLVM_DEBUG (dbgs () << " Checking " << *CheckInst << " \n " );
1271
1276
1272
1277
auto R = Info.getConstraintForSolving (Pred, A, B);
1273
1278
if (R.empty () || !R.isValid (Info)){
@@ -1292,13 +1297,10 @@ static std::optional<bool> checkCondition(CmpInst *Cmp, ConstraintInfo &Info,
1292
1297
return std::nullopt;
1293
1298
1294
1299
LLVM_DEBUG ({
1295
- if (*ImpliedCondition) {
1296
- dbgs () << " Condition " << *Cmp;
1297
- } else {
1298
- auto InversePred = Cmp->getInversePredicate ();
1299
- dbgs () << " Condition " << CmpInst::getPredicateName (InversePred) << " "
1300
- << *A << " , " << *B;
1301
- }
1300
+ dbgs () << " Condition " ;
1301
+ dumpUnpackedICmp (
1302
+ dbgs (), *ImpliedCondition ? Pred : CmpInst::getInversePredicate (Pred),
1303
+ A, B);
1302
1304
dbgs () << " implied by dominating constraints\n " ;
1303
1305
CSToUse.dump ();
1304
1306
});
@@ -1338,8 +1340,9 @@ static bool checkAndReplaceCondition(
1338
1340
return true ;
1339
1341
};
1340
1342
1341
- if (auto ImpliedCondition =
1342
- checkCondition (Cmp, Info, NumIn, NumOut, ContextInst))
1343
+ if (auto ImpliedCondition = checkCondition (
1344
+ Cmp->getPredicate (), Cmp->getOperand (0 ), Cmp->getOperand (1 ), Cmp,
1345
+ Info, NumIn, NumOut, ContextInst))
1343
1346
return ReplaceCmpWithConstant (Cmp, *ImpliedCondition);
1344
1347
return false ;
1345
1348
}
@@ -1380,9 +1383,10 @@ static bool checkAndSecondOpImpliedByFirst(
1380
1383
1381
1384
bool Changed = false ;
1382
1385
// Check if the second condition can be simplified now.
1383
- if (auto ImpliedCondition =
1384
- checkCondition (cast<ICmpInst>(And->getOperand (1 )), Info, CB.NumIn ,
1385
- CB.NumOut , CB.getContextInst ())) {
1386
+ ICmpInst *Cmp = cast<ICmpInst>(And->getOperand (1 ));
1387
+ if (auto ImpliedCondition = checkCondition (
1388
+ Cmp->getPredicate (), Cmp->getOperand (0 ), Cmp->getOperand (1 ), Cmp,
1389
+ Info, CB.NumIn , CB.NumOut , CB.getContextInst ())) {
1386
1390
And->setOperand (1 , ConstantInt::getBool (And->getType (), *ImpliedCondition));
1387
1391
Changed = true ;
1388
1392
}
@@ -1408,9 +1412,8 @@ void ConstraintInfo::addFact(CmpInst::Predicate Pred, Value *A, Value *B,
1408
1412
if (!R.isValid (*this ) || R.isNe ())
1409
1413
return ;
1410
1414
1411
- LLVM_DEBUG (dbgs () << " Adding '" << Pred << " " ;
1412
- A->printAsOperand (dbgs (), false ); dbgs () << " , " ;
1413
- B->printAsOperand (dbgs (), false ); dbgs () << " '\n " );
1415
+ LLVM_DEBUG (dbgs () << " Adding '" ; dumpUnpackedICmp (dbgs (), Pred, A, B);
1416
+ dbgs () << " '\n " );
1414
1417
bool Added = false ;
1415
1418
auto &CSToUse = getCS (R.IsSigned );
1416
1419
if (R.Coefficients .empty ())
@@ -1616,10 +1619,8 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
1616
1619
}
1617
1620
1618
1621
auto AddFact = [&](CmpInst::Predicate Pred, Value *A, Value *B) {
1619
- LLVM_DEBUG (dbgs () << " fact to add to the system: "
1620
- << CmpInst::getPredicateName (Pred) << " " ;
1621
- A->printAsOperand (dbgs ()); dbgs () << " , " ;
1622
- B->printAsOperand (dbgs (), false ); dbgs () << " \n " );
1622
+ LLVM_DEBUG (dbgs () << " fact to add to the system: " ;
1623
+ dumpUnpackedICmp (dbgs (), Pred, A, B); dbgs () << " \n " );
1623
1624
if (Info.getCS (CmpInst::isSigned (Pred)).size () > MaxRows) {
1624
1625
LLVM_DEBUG (
1625
1626
dbgs ()
0 commit comments