[llvm] [VPlan] Make canonical IV part of the region (PR #156262)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 11 10:07:42 PDT 2026
================
@@ -870,6 +881,41 @@ void VPRegionBlock::dissolveToCFGLoop() {
VPBlockUtils::connectBlocks(ExitingLatch, Header);
}
+VPInstruction *VPRegionBlock::getOrCreateCanonicalIVIncrement() {
+ // TODO: Represent the increment as VPRegionValue as well.
+ auto *ExitingLatch = cast<VPBasicBlock>(getExiting());
+ VPRegionValue *CanIV = getCanonicalIV();
+ assert(CanIV && "Expected a canonical IV");
+
+ auto *ExitingTerm = ExitingLatch->getTerminator();
+ VPInstruction *CanIVInc = nullptr;
+ // Try to match BranchOnCount(increment, trip_count) for main loop.
+ if (match(ExitingTerm,
+ m_BranchOnCount(m_VPInstruction(CanIVInc), m_VPValue()))) {
+ assert(match(CanIVInc, m_c_Add(m_Specific(CanIV), m_LiveIn())) &&
+ "unexpected increment");
+ return CanIVInc;
+ }
+
+ // Try to match BranchOnCond(ICmp EQ(increment, trip_count)) for epilogue
+ // loops or transformed loops (like using EVL or narrowing interleave groups).
+ VPValue *Cond = nullptr;
+ if ((match(ExitingTerm, m_BranchOnCond(m_VPValue(Cond))) &&
+ match(Cond,
+ m_SpecificICmp(CmpInst::ICMP_EQ, m_VPInstruction(CanIVInc),
+ m_Specific(&getPlan()->getVectorTripCount()))) &&
+ match(CanIVInc,
+ m_c_Add(m_CombineOr(m_Specific(CanIV),
+ m_c_Add(m_Specific(CanIV), m_LiveIn())),
+ m_VPValue()))))
+ return CanIVInc;
+
----------------
ayalz wrote:
Simpler to look for an Add of CanIV and VFxUF, before creating one, by looking at uses of VFxUF or CanIV, than to inspect BranchOnCount or BranchOnCond terminators it may feed?
https://github.com/llvm/llvm-project/pull/156262
More information about the llvm-commits
mailing list