Skip to content

Commit b72103e

Browse files
committed
[SCCP] Simplify general icmp instructions
1 parent 22a10c8 commit b72103e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

llvm/lib/Transforms/Utils/SCCPSolver.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ static Value *simplifyInstruction(SCCPSolver &Solver,
299299
Value *LHS = ICmp->getOperand(0);
300300
ICmpInst::Predicate Pred = ICmp->getPredicate();
301301
const APInt *Offset;
302+
// Match icmp X + Offset, C
302303
if (match(LHS, m_OneUse(m_AddLike(m_Value(X), m_APInt(Offset)))))
303304
return ConstantRange::makeExactICmpRegion(Pred, *RHSC).sub(*Offset);
304305
// Match icmp eq/ne X & NegPow2, C
@@ -310,7 +311,10 @@ static Value *simplifyInstruction(SCCPSolver &Solver,
310311
return Pred == ICmpInst::ICMP_EQ ? CR : CR.inverse();
311312
}
312313
}
313-
return std::nullopt;
314+
// Fallback: Match icmp X, C
315+
// E.g., if X ∈ [0, 4], this can simplify icmp uge X, 4 to icmp eq X, 4
316+
X = LHS;
317+
return ConstantRange::makeExactICmpRegion(Pred, *RHSC);
314318
};
315319

316320
if (auto CR = MatchTwoInstructionExactRangeCheck()) {

0 commit comments

Comments
 (0)