[llvm] Fold (a % b) lt/ge (b-1) where b is a power of 2 (PR #72504)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 17 08:33:22 PST 2023
elhewaty wrote:
Does llvm.assume require special handling?
```
{
Value *X;
const APInt *C, *CC;
ICmpInst::Predicate Pred = I.getPredicate();
if ((Pred == ICmpInst::ICMP_SGE || Pred == ICmpInst::ICMP_SLT) &&
match(Op0, m_OneUse(m_SRem(m_Value(X), m_APInt(C)))) &&
match(Op1, m_OneUse(m_Add(m_SpecificInt(*C), m_APInt(CC)))) &&
!(C->isNegative()) && *CC == -1) {
// icmp slt (X % C), (C - 1) --> icmp ne (X % C), (C - 1)
auto *NewCmp = Builder.CreateICmpNE(Op0, Op1);
// icmp sge (X % C), (C - 1) --> icmp eq (X % C), (C - 1)
if (Pred == ICmpInst::ICMP_SGE)
NewCmp = Builder.CreateICmpEQ(Op0, Op1);
return replaceInstUsesWith(I, NewCmp);
}
}
```
This code doesn't change the tests.
https://github.com/llvm/llvm-project/pull/72504
More information about the llvm-commits
mailing list