[llvm] [VPlan] Make canonical IV part of the region (PR #156262)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 22 08:54:26 PST 2026
================
@@ -870,6 +889,37 @@ void VPRegionBlock::dissolveToCFGLoop() {
VPBlockUtils::connectBlocks(ExitingLatch, Header);
}
+VPInstruction *VPRegionBlock::getOrCreateCanonicalIVIncrement() {
+ // TODO: Represent the increment as VPRegionValue as well.
+ auto *ExitingLatch = cast<VPBasicBlock>(getExiting());
+ VPValue *CanIV = getCanonicalIV();
+ assert(CanIV && "Expected a canonical IV");
+
+ // Match CanIV + Step or (CanIV + ResumeVal) + Step for epilogue loops.
+ auto m_CanIVIncrement = [CanIV]() {
+ return m_c_Add(
+ m_CombineOr(m_Specific(CanIV), m_c_Add(m_Specific(CanIV), m_LiveIn())),
+ m_VPValue());
+ };
+
+ 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()))) {
+ // Try to match BranchOnCond(ICmp EQ(increment, trip_count)) for epilogue.
+ VPValue *Cond = nullptr;
+ if (!(match(ExitingTerm, m_BranchOnCond(m_VPValue(Cond))) &&
+ match(Cond, m_SpecificICmp(CmpInst::ICMP_EQ,
+ m_VPInstruction(CanIVInc), m_VPValue())) &&
+ match(CanIVInc, m_CanIVIncrement())))
+ CanIVInc = nullptr;
+ }
+ assert(!CanIVInc || match(CanIVInc, m_CanIVIncrement()) &&
+ "invalid existing IV increment");
----------------
ayalz wrote:
```suggestion
// Try to match BranchOnCond(ICmp EQ(increment, trip_count)) for epilogue.
VPValue *Cond = nullptr;
if (match(ExitingTerm, m_BranchOnCond(m_VPValue(Cond))) &&
match(Cond, m_SpecificICmp(CmpInst::ICMP_EQ,
m_VPInstruction(CanIVInc), m_VPValue())) &&
match(CanIVInc, m_CanIVIncrement()))
return CanIVInc;
```
where m_CanIVIncrement() is simplified to check epilog case only.
https://github.com/llvm/llvm-project/pull/156262
More information about the llvm-commits
mailing list