[llvm] [VPlan] Permit licm-sinking recipes with no users (PR #189957)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 06:16:19 PDT 2026
================
@@ -2732,42 +2734,36 @@ 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;
+ // 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.
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) {
+ if (any_of(Def->users(), [&SinkBB, &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;
+ // TODO: If the user is a PHI node, we should check the block of
+ // incoming value.
+ return UserR->isPhi() || Parent->getEnclosingLoopRegion() ||
+ Parent->getSinglePredecessor() != LoopRegion;
}))
continue;
- // Only sink to dedicated exit blocks of the loop region.
- if (SinkBB->getSinglePredecessor() != LoopRegion)
+ // Attempt to set SinkBB to the LoopRegion's single successor, if one
+ // wasn't found.
+ if (!SinkBB && !(SinkBB = cast_or_null<VPBasicBlock>(
+ LoopRegion->getSingleSuccessor())))
continue;
- // TODO: This will need to be a check instead of a assert after
- // conditional branches in vectorized loops are supported.
+ // This will need to be a check instead of a assert after conditional
----------------
fhahn wrote:
this still remains a TODO?
https://github.com/llvm/llvm-project/pull/189957
More information about the llvm-commits
mailing list