[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).
----------------
ayalz wrote:

Independent: `BranchOnCond(increment == trip_count)` should arguably be canonicalized into `BranchOnCount(increment, trip_count)` for any countable loop, including epilog and EVL loops, where `convertToConcreteRecipes()` turns the latter into the former. Unless EVL or some other transformation prefers to lose the loop's countability.

https://github.com/llvm/llvm-project/pull/156262


More information about the llvm-commits mailing list