[llvm] [InstCombine] Fold (X / C) < X and (X >> C) < X into X > 0 (PR #85555)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 16 15:48:40 PDT 2024
================
@@ -7406,6 +7406,31 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
if (Instruction *Res = foldReductionIdiom(I, Builder, DL))
return Res;
+ // Folding (X / Y) < X => X > 0 for some constant Y other than 0 or 1
+ {
+ Constant *Divisor;
+ Value *Dividend;
+ if (match(Op0,
+ m_CombineOr(m_SDiv(m_Value(Dividend), m_ImmConstant(Divisor)),
+ m_UDiv(m_Value(Dividend), m_ImmConstant(Divisor)))) &&
+ match(Op1, m_Deferred(Dividend)) &&
+ !(Divisor->isZeroValue() || Divisor->isOneValue())) {
+ return new ICmpInst(ICmpInst::ICMP_SGT, Dividend,
----------------
goldsteinn wrote:
Also note you can handle just about any predicate here.
For `sdiv`/`ashr`, you need `!ICmpInst::isUnsigned(I.getPredicate())`. For `udiv`/`lshr`, any predicate works.
https://github.com/llvm/llvm-project/pull/85555
More information about the llvm-commits
mailing list