[llvm] Missed optimization when `b - a` is known nonnegative inside `select` instruction (PR #187898)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 3 15:03:03 PDT 2026
================
@@ -664,10 +664,49 @@ static Value *foldSelectICmpMinMax(const ICmpInst *Cmp, Value *TVal,
Value *FVal,
InstCombiner::BuilderTy &Builder,
const SimplifyQuery &SQ) {
- const Value *CmpLHS = Cmp->getOperand(0);
- const Value *CmpRHS = Cmp->getOperand(1);
+ Value *CmpLHS = Cmp->getOperand(0);
+ Value *CmpRHS = Cmp->getOperand(1);
ICmpInst::Predicate Pred = Cmp->getPredicate();
+ if (match(TVal, m_Zero())) {
+ // (X <= Y) ? 0 : (X - Y)
+ if ((Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SLE) &&
+ match(FVal, m_NSWSub(m_Specific(CmpLHS), m_Specific(CmpRHS))) &&
+ isGuaranteedNotToBeUndef(CmpLHS, nullptr, Cmp, nullptr)) {
----------------
user1342234 wrote:
Thanks, I mis-read your previous suggestion.
https://github.com/llvm/llvm-project/pull/187898
More information about the llvm-commits
mailing list