@@ -1334,27 +1334,22 @@ Instruction *InstCombinerImpl::foldICmpWithDominatingICmp(ICmpInst &Cmp) {
1334
1334
// We already checked simple implication in InstSimplify, only handle complex
1335
1335
// cases here.
1336
1336
Value *X = Cmp.getOperand (0 ), *Y = Cmp.getOperand (1 );
1337
- ICmpInst::Predicate DomPred;
1338
1337
const APInt *C;
1339
1338
if (!match (Y, m_APInt (C)))
1340
1339
return nullptr ;
1341
1340
1342
1341
CmpInst::Predicate Pred = Cmp.getPredicate ();
1343
1342
ConstantRange CR = ConstantRange::makeExactICmpRegion (Pred, *C);
1344
1343
1345
- auto handleDomCond = [&](Value *DomCond, bool CondIsTrue) -> Instruction * {
1346
- const APInt *DomC;
1347
- if (!match (DomCond, m_ICmp (DomPred, m_Specific (X), m_APInt (DomC))))
1348
- return nullptr ;
1344
+ auto handleDomCond = [&](ICmpInst::Predicate DomPred,
1345
+ const APInt *DomC) -> Instruction * {
1349
1346
// We have 2 compares of a variable with constants. Calculate the constant
1350
1347
// ranges of those compares to see if we can transform the 2nd compare:
1351
1348
// DomBB:
1352
1349
// DomCond = icmp DomPred X, DomC
1353
1350
// br DomCond, CmpBB, FalseBB
1354
1351
// CmpBB:
1355
1352
// Cmp = icmp Pred X, C
1356
- if (!CondIsTrue)
1357
- DomPred = CmpInst::getInversePredicate (DomPred);
1358
1353
ConstantRange DominatingCR =
1359
1354
ConstantRange::makeExactICmpRegion (DomPred, *DomC);
1360
1355
ConstantRange Intersection = DominatingCR.intersectWith (CR);
@@ -1388,15 +1383,21 @@ Instruction *InstCombinerImpl::foldICmpWithDominatingICmp(ICmpInst &Cmp) {
1388
1383
};
1389
1384
1390
1385
for (BranchInst *BI : DC.conditionsFor (X)) {
1391
- auto *Cond = BI->getCondition ();
1386
+ ICmpInst::Predicate DomPred;
1387
+ const APInt *DomC;
1388
+ if (!match (BI->getCondition (),
1389
+ m_ICmp (DomPred, m_Specific (X), m_APInt (DomC))))
1390
+ continue ;
1391
+
1392
1392
BasicBlockEdge Edge0 (BI->getParent (), BI->getSuccessor (0 ));
1393
1393
if (DT.dominates (Edge0, Cmp.getParent ())) {
1394
- if (auto *V = handleDomCond (Cond, true ))
1394
+ if (auto *V = handleDomCond (DomPred, DomC ))
1395
1395
return V;
1396
1396
} else {
1397
1397
BasicBlockEdge Edge1 (BI->getParent (), BI->getSuccessor (1 ));
1398
1398
if (DT.dominates (Edge1, Cmp.getParent ()))
1399
- if (auto *V = handleDomCond (Cond, false ))
1399
+ if (auto *V =
1400
+ handleDomCond (CmpInst::getInversePredicate (DomPred), DomC))
1400
1401
return V;
1401
1402
}
1402
1403
}
0 commit comments