[llvm] [InstCombine] Fold (X / C) < X and (X >> C) < X into X > 0 (PR #85555)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 00:36:51 PDT 2024
================
@@ -7103,6 +7103,39 @@ Instruction *InstCombinerImpl::foldICmpCommutative(ICmpInst::Predicate Pred,
if (Value *V = foldICmpWithLowBitMaskedVal(Pred, Op0, Op1, Q, *this))
return replaceInstUsesWith(CxtI, V);
+ // Folding (X / Y) pred X => X ~pred 0 for some constant Y other than 0 or 1
+ {
+ const APInt *Divisor;
+ if (match(Op0, m_UDiv(m_Specific(Op1), m_APInt(Divisor))) &&
+ Divisor->ugt(1)) {
----------------
nikic wrote:
Worth noting that this condition could be != 1 rather than > 1, because division by zero is UB anyway. Ultimately makes no difference in terms of behavior though, so your variant is fine as well.
https://github.com/llvm/llvm-project/pull/85555
More information about the llvm-commits
mailing list