[llvm] [IVDesc] Use SCEVPatternMatch to improve code (NFC) (PR #168397)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 24 04:17:57 PST 2025
================
@@ -1614,41 +1617,30 @@ bool InductionDescriptor::isInductionPHI(
// Check that the PHI is consecutive.
const SCEV *PhiScev = Expr ? Expr : SE->getSCEV(Phi);
- const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PhiScev);
+ const SCEV *Step;
- if (!AR) {
+ // FIXME: We are currently matching the specific loop TheLoop; if it doesn't
+ // match, we should treat it as a uniform. Unfortunately, we don't currently
+ // know how to handled uniform PHIs.
+ if (!match(PhiScev, m_scev_AffineAddRec(m_SCEV(), m_SCEV(Step),
+ m_SpecificLoop(TheLoop)))) {
LLVM_DEBUG(dbgs() << "LV: PHI is not a poly recurrence.\n");
return false;
}
- if (AR->getLoop() != TheLoop) {
- // FIXME: We should treat this as a uniform. Unfortunately, we
- // don't currently know how to handled uniform PHIs.
- LLVM_DEBUG(
- dbgs() << "LV: PHI is a recurrence with respect to an outer loop.\n");
- return false;
- }
-
// This function assumes that InductionPhi is called only on Phi nodes
// present inside loop headers. Check for the same, and throw an assert if
// the current Phi is not present inside the loop header.
- assert(Phi->getParent() == AR->getLoop()->getHeader()
- && "Invalid Phi node, not present in loop header");
+ assert(Phi->getParent() == TheLoop->getHeader() &&
+ "Invalid Phi node, not present in loop header");
Value *StartValue =
- Phi->getIncomingValueForBlock(AR->getLoop()->getLoopPreheader());
+ Phi->getIncomingValueForBlock(TheLoop->getLoopPreheader());
- BasicBlock *Latch = AR->getLoop()->getLoopLatch();
+ BasicBlock *Latch = TheLoop->getLoopLatch();
if (!Latch)
return false;
- const SCEV *Step = AR->getStepRecurrence(*SE);
- // Calculate the pointer stride and check if it is consecutive.
- // The stride may be a constant or a loop invariant integer value.
- const SCEVConstant *ConstStep = dyn_cast<SCEVConstant>(Step);
----------------
david-arm wrote:
You can have a loop-invariant step that's not a constant so I don't think you can drop the check for Step == SCEVConstant. I think you need to adapt the new `match` pattern above to look for a SCEVConstant.
https://github.com/llvm/llvm-project/pull/168397
More information about the llvm-commits
mailing list