[llvm] [VPlan] Fix broadcasted values using loop region during execution (PR #142594)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 11 16:14:07 PDT 2025
https://github.com/lukel97 updated https://github.com/llvm/llvm-project/pull/142594
>From cf4a828aaeab0be4c65eee1718d9e292b6a19150 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Wed, 11 Jun 2025 23:49:19 +0100
Subject: [PATCH] [VPlan] Remove hoisting to preheader in VPTransformState::get
Now that the start values of reductions are explicitly modelled as a VPInstruction in 6108d50, we no longer really need to hoist when executing.
>From the discussion in https://github.com/llvm/llvm-project/pull/142594#discussion_r2140339682
---
llvm/lib/Transforms/Vectorize/VPlan.cpp | 30 ++++---------------------
1 file changed, 4 insertions(+), 26 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 1838562f26b82..104fb6a387b96 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -289,34 +289,12 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
if (hasVectorValue(Def))
return Data.VPV2Vector[Def];
- auto GetBroadcastInstrs = [this, Def](Value *V) {
- bool SafeToHoist =
- !Def->hasDefiningRecipe() ||
- VPDT.properlyDominates(Def->getDefiningRecipe()->getParent(),
- Plan->getVectorPreheader());
-
- if (VF.isScalar())
- return V;
- // Place the code for broadcasting invariant variables in the new preheader.
- IRBuilder<>::InsertPointGuard Guard(Builder);
- if (SafeToHoist) {
- BasicBlock *LoopVectorPreHeader =
- CFG.VPBB2IRBB[Plan->getVectorPreheader()];
- if (LoopVectorPreHeader)
- Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator());
- }
-
- // Place the code for broadcasting invariant variables in the new preheader.
- // Broadcast the scalar into all locations in the vector.
- Value *Shuf = Builder.CreateVectorSplat(VF, V, "broadcast");
-
- return Shuf;
- };
-
if (!hasScalarValue(Def, {0})) {
assert(Def->isLiveIn() && "expected a live-in");
Value *IRV = Def->getLiveInIRValue();
- Value *B = GetBroadcastInstrs(IRV);
+ if (VF.isScalar())
+ return IRV;
+ Value *B = Builder.CreateVectorSplat(VF, IRV, "broadcast");
set(Def, B);
return B;
}
@@ -361,7 +339,7 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
// insertelements once.
Value *VectorValue = nullptr;
if (IsSingleScalar) {
- VectorValue = GetBroadcastInstrs(ScalarValue);
+ VectorValue = Builder.CreateVectorSplat(VF, ScalarValue, "broadcast");
set(Def, VectorValue);
} else {
// Initialize packing with insertelements to start from undef.
More information about the llvm-commits
mailing list