[llvm] [CodeGenPrepare] Folding `urem` with loop invariant value as remainder (PR #96625)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 12:23:50 PDT 2024
================
@@ -1974,6 +1975,133 @@ static bool foldFCmpToFPClassTest(CmpInst *Cmp, const TargetLowering &TLI,
return true;
}
+static bool isRemOfLoopIncrementWithLoopInvariant(Instruction *Rem,
+ const LoopInfo *LI,
+ Value *&RemAmtOut,
+ PHINode *&LoopIncrPNOut) {
+ Value *Incr, *RemAmt;
+ // NB: If RemAmt is a power of 2 it *should* have been transformed by now.
+ if (!match(Rem, m_URem(m_Value(Incr), m_Value(RemAmt))))
+ return false;
+
+ // Only trivially analyzable loops.
+ Loop *L = LI->getLoopFor(Rem->getParent());
+ if (!L || !L->getLoopPreheader() || !L->getLoopLatch())
----------------
nikic wrote:
IIRC getLoopPreheader is expensive, so maybe those this after the phi check.
https://github.com/llvm/llvm-project/pull/96625
More information about the llvm-commits
mailing list