[llvm] 9f7a155 - [VPlan] Update packScalarIntoVector to take and return wide value (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 21 10:06:17 PDT 2025
Author: Florian Hahn
Date: 2025-06-21T18:03:14+01:00
New Revision: 9f7a15539441cc589c4116de43e752c9c62cafef
URL: https://github.com/llvm/llvm-project/commit/9f7a15539441cc589c4116de43e752c9c62cafef
DIFF: https://github.com/llvm/llvm-project/commit/9f7a15539441cc589c4116de43e752c9c62cafef.diff
LOG: [VPlan] Update packScalarIntoVector to take and return wide value (NFC)
Make the function more flexible in preparation for new users.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlanHelpers.h
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 773a5a4a829c7..a3f39f5ad7a29 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -364,13 +364,12 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
VectorValue = GetBroadcastInstrs(ScalarValue);
set(Def, VectorValue);
} else {
- // Initialize packing with insertelements to start from undef.
assert(!VF.isScalable() && "VF is assumed to be non scalable.");
- Value *Undef = PoisonValue::get(toVectorizedTy(LastInst->getType(), VF));
- set(Def, Undef);
+ // Initialize packing with insertelements to start from poison.
+ VectorValue = PoisonValue::get(toVectorizedTy(LastInst->getType(), VF));
for (unsigned Lane = 0; Lane < VF.getFixedValue(); ++Lane)
- packScalarIntoVectorizedValue(Def, Lane);
- VectorValue = get(Def);
+ VectorValue = packScalarIntoVectorizedValue(Def, VectorValue, Lane);
+ set(Def, VectorValue);
}
Builder.restoreIP(OldIP);
return VectorValue;
@@ -398,10 +397,10 @@ void VPTransformState::setDebugLocFrom(DebugLoc DL) {
Builder.SetCurrentDebugLocation(DL);
}
-void VPTransformState::packScalarIntoVectorizedValue(const VPValue *Def,
- const VPLane &Lane) {
+Value *VPTransformState::packScalarIntoVectorizedValue(const VPValue *Def,
+ Value *WideValue,
+ const VPLane &Lane) {
Value *ScalarInst = get(Def, Lane);
- Value *WideValue = get(Def);
Value *LaneExpr = Lane.getAsRuntimeExpr(Builder, VF);
if (auto *StructTy = dyn_cast<StructType>(WideValue->getType())) {
// We must handle each element of a vectorized struct type.
@@ -415,7 +414,7 @@ void VPTransformState::packScalarIntoVectorizedValue(const VPValue *Def,
} else {
WideValue = Builder.CreateInsertElement(WideValue, ScalarInst, LaneExpr);
}
- set(Def, WideValue);
+ return WideValue;
}
BasicBlock *VPBasicBlock::createEmptyBasicBlock(VPTransformState &State) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanHelpers.h b/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
index 0446991ebfff3..f33f94b7162c6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
@@ -286,9 +286,10 @@ struct VPTransformState {
/// Set the debug location in the builder using the debug location \p DL.
void setDebugLocFrom(DebugLoc DL);
- /// Construct the vectorized value of a scalarized value \p V one lane at a
- /// time.
- void packScalarIntoVectorizedValue(const VPValue *Def, const VPLane &Lane);
+ /// Insert the scalar value of \p Def at \p Lane into \p Lane of \p WideValue
+ /// and return the resulting value.
+ Value *packScalarIntoVectorizedValue(const VPValue *Def, Value *WideValue,
+ const VPLane &Lane);
/// Hold state information used when constructing the CFG of the output IR,
/// traversing the VPBasicBlocks and generating corresponding IR BasicBlocks.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 3d237de5fa8de..3e12fdf9163eb 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2634,14 +2634,16 @@ void VPReplicateRecipe::execute(VPTransformState &State) {
scalarizeInstruction(UI, this, *State.Lane, State);
// Insert scalar instance packing it into a vector.
if (State.VF.isVector() && shouldPack()) {
+ Value *WideValue;
// If we're constructing lane 0, initialize to start from poison.
if (State.Lane->isFirstLane()) {
assert(!State.VF.isScalable() && "VF is assumed to be non scalable.");
- Value *Poison =
- PoisonValue::get(VectorType::get(UI->getType(), State.VF));
- State.set(this, Poison);
+ WideValue = PoisonValue::get(VectorType::get(UI->getType(), State.VF));
+ } else {
+ WideValue = State.get(this);
}
- State.packScalarIntoVectorizedValue(this, *State.Lane);
+ State.set(this, State.packScalarIntoVectorizedValue(this, WideValue,
+ *State.Lane));
}
return;
}
More information about the llvm-commits
mailing list