[llvm] [CGP] [CodeGenPrepare] Folding `urem` with loop invariant value plus offset (PR #104724)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 10:20:23 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))))
----------------
goldsteinn wrote:
We could, although Im not sure exactly what we would want in a PHI matcher? Would we support matching BBs? Variable number of arguments or "binary" phis only? Etc...
Either way, I think that its a conversation that is a bit beyond the scope of this particular use case and PR.
https://github.com/llvm/llvm-project/pull/104724
More information about the llvm-commits
mailing list