[llvm] [CGP] [CodeGenPrepare] Folding `urem` with loop invariant value plus offset (PR #104724)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 04:09:02 PDT 2024
================
@@ -1982,17 +1982,36 @@ static bool foldFCmpToFPClassTest(CmpInst *Cmp, const TargetLowering &TLI,
return true;
}
-static bool isRemOfLoopIncrementWithLoopInvariant(Instruction *Rem,
- const LoopInfo *LI,
- Value *&RemAmtOut,
- PHINode *&LoopIncrPNOut) {
+static bool isRemOfLoopIncrementWithLoopInvariant(
+ Instruction *Rem, const LoopInfo *LI, Value *&RemAmtOut, Value *&AddInstOut,
+ Value *&AddOffsetOut, 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;
+ Value *AddInst, *AddOffset;
// Find out loop increment PHI.
auto *PN = dyn_cast<PHINode>(Incr);
+ if (PN != nullptr) {
+ AddInst = nullptr;
+ AddOffset = nullptr;
+ } else {
+ // Search through a NUW add on top of the loop increment.
+ Value *V0, *V1;
+ if (!match(Incr, m_NUWAdd(m_Value(V0), m_Value(V1))))
----------------
RKSimon wrote:
Would it be worth adding a m_PHI matcher - we could then use m_c_NUWAdd and avoid the messy commutative matching below.
https://github.com/llvm/llvm-project/pull/104724
More information about the llvm-commits
mailing list