[llvm] [CodeGenPrepare] Folding `urem` with loop invariant value as remainder (PR #96625)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 08:16:53 PDT 2024
================
@@ -1974,6 +1975,165 @@ static bool foldFCmpToFPClassTest(CmpInst *Cmp, const TargetLowering &TLI,
return true;
}
+static bool isRemOfLoopIncrementWithLoopInvariant(
+ Value *Rem, const LoopInfo *LI, Value *&RemAmtOut,
+ std::optional<bool> &AddOrSubOut, Value *&AddOrSubOffsetOut,
+ PHINode *&LoopIncrPNOut) {
+ Value *Incr, *RemAmt;
+ if (!isa<Instruction>(Rem))
+ return false;
+ // 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(cast<Instruction>(Rem)->getParent());
+ if (L == nullptr || L->getLoopPreheader() == nullptr ||
+ L->getLoopLatch() == nullptr)
----------------
nikic wrote:
Use `!` instead of `== nullptr`.
https://github.com/llvm/llvm-project/pull/96625
More information about the llvm-commits
mailing list