[llvm] [VPlan] Don't collect live-ins in collectUsersInExitBlocks. (NFC) (PR #123819)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 13:12:43 PST 2025


https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/123819

Live-ins don't need to be handled, other than adding to the exit phi recipe. Do that early and assert that otherwise the exit value is defined in the vector loop region.

This should enable simply skipping other exit values that do not need further fixing, e.g. if handling the exit value from the early exit directly in handleUncountableEarlyExit.

>From 0f992a3bb9ba96780f98a38f534a47aa333606d3 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Tue, 21 Jan 2025 19:29:21 +0000
Subject: [PATCH] [VPlan] Don't collect live-ins in collectUsersInExitBlocks.
 (NFC)

Live-ins don't need to be handled, other than adding to the exit phi
recipe. Do that early and assert that otherwise the exit value is
defined in the vector loop region.

This should enable simply skipping other exit values that do not need
further fixing, e.g. if handling the exit value from the early exit
directly in handleUncountableEarlyExit.
---
 llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index df64bb2884ab88..68406ecdff096c 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9052,8 +9052,12 @@ collectUsersInExitBlocks(Loop *OrigLoop, VPRecipeBuilder &Builder,
         }
         Value *IncomingValue = ExitPhi->getIncomingValueForBlock(ExitingBB);
         VPValue *V = Builder.getVPValueOrAddLiveIn(IncomingValue);
-        ExitUsersToFix.insert(ExitIRI);
         ExitIRI->addOperand(V);
+        if (V->isLiveIn())
+          continue;
+        assert(V->getDefiningRecipe()->getParent()->getEnclosingLoopRegion() &&
+               "Only recipes defined inside a region should need fixing.");
+        ExitUsersToFix.insert(ExitIRI);
       }
     }
   }
@@ -9077,11 +9081,6 @@ addUsersInExitBlocks(VPlan &Plan,
   // modeling the corresponding LCSSA phis.
   for (VPIRInstruction *ExitIRI : ExitUsersToFix) {
     for (const auto &[Idx, Op] : enumerate(ExitIRI->operands())) {
-      // Pass live-in values used by exit phis directly through to their users
-      // in the exit block.
-      if (Op->isLiveIn())
-        continue;
-
       // Currently only live-ins can be used by exit values from blocks not
       // exiting via the vector latch through to the middle block.
       if (ExitIRI->getParent()->getSinglePredecessor() != MiddleVPBB)



More information about the llvm-commits mailing list