[llvm] [VPlan] Generalize licm-sink to strip zero-user bail (PR #187077)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 04:22:21 PDT 2026


================
@@ -2703,43 +2702,47 @@ static void licm(VPlan &Plan) {
       // TODO: Use R.definedValues() instead of casting to VPSingleDefRecipe to
       // support recipes with multiple defined values (e.g., interleaved loads).
       auto *Def = cast<VPSingleDefRecipe>(&R);
-      // Skip recipes without users as we cannot determine a sink block.
-      // TODO: Clone sinkable recipes without users to all exit blocks to reduce
-      // their execution frequency.
-      if (Def->getNumUsers() == 0)
-        continue;
 
-      VPBasicBlock *SinkBB = nullptr;
-      // Cannot sink the recipe if any user
-      //  * is defined in any loop region, or
-      //  * is a phi, or
-      //  * multiple users in different blocks.
-      if (any_of(Def->users(), [&SinkBB](VPUser *U) {
+      // Cannot sink the recipe if the user is defined in a loop region or a
+      // non-successor of the vector loop region. Cannot sink if user is a phi
+      // either.
+      if (any_of(Def->users(), [&LoopRegion](VPUser *U) {
             auto *UserR = cast<VPRecipeBase>(U);
             VPBasicBlock *Parent = UserR->getParent();
             // TODO: If the user is a PHI node, we should check the block of
             // incoming value. Support PHI node users if needed.
-            if (UserR->isPhi() || Parent->getEnclosingLoopRegion())
-              return true;
-            // TODO: Support sinking when users are in multiple blocks.
-            if (SinkBB && SinkBB != Parent)
-              return true;
-            SinkBB = Parent;
-            return false;
+            return UserR->isPhi() || Parent->getEnclosingLoopRegion() ||
+                   Parent->getSinglePredecessor() != LoopRegion;
           }))
         continue;
 
-      // Only sink to dedicated exit blocks of the loop region.
-      if (SinkBB->getSinglePredecessor() != LoopRegion)
-        continue;
----------------
fhahn wrote:

The patch also removes the restriction for sinking to a single block. Could we split this up to allow recipes without users to be sunk if the region has a single successor, as in the modified test?

I think the Sinking and cloning in multiple successor blocks is currently untested?

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


More information about the llvm-commits mailing list