[llvm] [VPlan] Make CanIV part of region. (PR #144803)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 10 05:12:54 PDT 2025


================
@@ -894,18 +902,37 @@ void VPRegionBlock::print(raw_ostream &O, const Twine &Indent,
 
 void VPRegionBlock::dissolveToCFGLoop() {
   auto *Header = cast<VPBasicBlock>(getEntry());
-  if (auto *CanIV = dyn_cast<VPCanonicalIVPHIRecipe>(&Header->front())) {
-    assert(this == getPlan()->getVectorLoopRegion() &&
-           "Canonical IV must be in the entry of the top-level loop region");
-    auto *ScalarR = VPBuilder(CanIV).createScalarPhi(
-        {CanIV->getStartValue(), CanIV->getBackedgeValue()},
-        CanIV->getDebugLoc(), "index");
+  auto *ExitingLatch = cast<VPBasicBlock>(getExiting());
+  if (CanIV && CanIV->getNumUsers() > 0) {
+    auto *ExitingTerm = ExitingLatch->getTerminator();
+    VPInstruction *CanIVInc = nullptr;
+    for (VPUser *U : CanIV->users()) {
+      if (match(U, m_Add(m_VPValue(), m_Specific(&getPlan()->getVFxUF())))) {
+        CanIVInc = cast<VPInstruction>(U);
----------------
ayalz wrote:

```suggestion
        assert(!CanIVInc && "Expecting at most one canonical IV increment");
        CanIVInc = cast<VPInstruction>(U);
```
?

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


More information about the llvm-commits mailing list