Skip to content

Commit 9f7a155

Browse files
committed
[VPlan] Update packScalarIntoVector to take and return wide value (NFC)
Make the function more flexible in preparation for new users.
1 parent 4c1a100 commit 9f7a155

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,12 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
364364
VectorValue = GetBroadcastInstrs(ScalarValue);
365365
set(Def, VectorValue);
366366
} else {
367-
// Initialize packing with insertelements to start from undef.
368367
assert(!VF.isScalable() && "VF is assumed to be non scalable.");
369-
Value *Undef = PoisonValue::get(toVectorizedTy(LastInst->getType(), VF));
370-
set(Def, Undef);
368+
// Initialize packing with insertelements to start from poison.
369+
VectorValue = PoisonValue::get(toVectorizedTy(LastInst->getType(), VF));
371370
for (unsigned Lane = 0; Lane < VF.getFixedValue(); ++Lane)
372-
packScalarIntoVectorizedValue(Def, Lane);
373-
VectorValue = get(Def);
371+
VectorValue = packScalarIntoVectorizedValue(Def, VectorValue, Lane);
372+
set(Def, VectorValue);
374373
}
375374
Builder.restoreIP(OldIP);
376375
return VectorValue;
@@ -398,10 +397,10 @@ void VPTransformState::setDebugLocFrom(DebugLoc DL) {
398397
Builder.SetCurrentDebugLocation(DL);
399398
}
400399

401-
void VPTransformState::packScalarIntoVectorizedValue(const VPValue *Def,
402-
const VPLane &Lane) {
400+
Value *VPTransformState::packScalarIntoVectorizedValue(const VPValue *Def,
401+
Value *WideValue,
402+
const VPLane &Lane) {
403403
Value *ScalarInst = get(Def, Lane);
404-
Value *WideValue = get(Def);
405404
Value *LaneExpr = Lane.getAsRuntimeExpr(Builder, VF);
406405
if (auto *StructTy = dyn_cast<StructType>(WideValue->getType())) {
407406
// We must handle each element of a vectorized struct type.
@@ -415,7 +414,7 @@ void VPTransformState::packScalarIntoVectorizedValue(const VPValue *Def,
415414
} else {
416415
WideValue = Builder.CreateInsertElement(WideValue, ScalarInst, LaneExpr);
417416
}
418-
set(Def, WideValue);
417+
return WideValue;
419418
}
420419

421420
BasicBlock *VPBasicBlock::createEmptyBasicBlock(VPTransformState &State) {

llvm/lib/Transforms/Vectorize/VPlanHelpers.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ struct VPTransformState {
286286
/// Set the debug location in the builder using the debug location \p DL.
287287
void setDebugLocFrom(DebugLoc DL);
288288

289-
/// Construct the vectorized value of a scalarized value \p V one lane at a
290-
/// time.
291-
void packScalarIntoVectorizedValue(const VPValue *Def, const VPLane &Lane);
289+
/// Insert the scalar value of \p Def at \p Lane into \p Lane of \p WideValue
290+
/// and return the resulting value.
291+
Value *packScalarIntoVectorizedValue(const VPValue *Def, Value *WideValue,
292+
const VPLane &Lane);
292293

293294
/// Hold state information used when constructing the CFG of the output IR,
294295
/// traversing the VPBasicBlocks and generating corresponding IR BasicBlocks.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,14 +2634,16 @@ void VPReplicateRecipe::execute(VPTransformState &State) {
26342634
scalarizeInstruction(UI, this, *State.Lane, State);
26352635
// Insert scalar instance packing it into a vector.
26362636
if (State.VF.isVector() && shouldPack()) {
2637+
Value *WideValue;
26372638
// If we're constructing lane 0, initialize to start from poison.
26382639
if (State.Lane->isFirstLane()) {
26392640
assert(!State.VF.isScalable() && "VF is assumed to be non scalable.");
2640-
Value *Poison =
2641-
PoisonValue::get(VectorType::get(UI->getType(), State.VF));
2642-
State.set(this, Poison);
2641+
WideValue = PoisonValue::get(VectorType::get(UI->getType(), State.VF));
2642+
} else {
2643+
WideValue = State.get(this);
26432644
}
2644-
State.packScalarIntoVectorizedValue(this, *State.Lane);
2645+
State.set(this, State.packScalarIntoVectorizedValue(this, WideValue,
2646+
*State.Lane));
26452647
}
26462648
return;
26472649
}

0 commit comments

Comments
 (0)