[PATCH] D143883: [InstCombine] canonicalize urem as cmp+select
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 14 00:39:12 PST 2023
nikic requested changes to this revision.
nikic added a comment.
This revision now requires changes to proceed.
Needs more tests for preconditions, e.g. what happens if the constant is not 1?
Note that there is also a more general form of this fold, see https://github.com/llvm/llvm-project/blob/697a162fa63df328ec9ca334636c5e85390b2bf0/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp#L806. The tricky bit here is that we would nee `X < 2*Y`, which is hard to establish as a precondition in this context.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:1791
+ // Value *X;
+ if (match(Op0, m_NUWAdd(m_Value(X), m_One())) &&
+ simplifyICmpWithDominatingAssume(ICmpInst::ICMP_ULT, X, Op1, SQ, &I)) {
----------------
Why the nuw requirement? Seems to be fine without it? https://alive2.llvm.org/ce/z/uo7HMz
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:1792
+ if (match(Op0, m_NUWAdd(m_Value(X), m_One())) &&
+ simplifyICmpWithDominatingAssume(ICmpInst::ICMP_ULT, X, Op1, SQ, &I)) {
+ Value *Cmp = Builder.CreateICmpEQ(Op0, Op1);
----------------
Why is this specific to assumes? Can we do a generic simplifyICmp? (If we do so, Op0 needs to be frozen.)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143883/new/
https://reviews.llvm.org/D143883
More information about the llvm-commits
mailing list