Skip to content

Commit cf4a828

Browse files
committed
[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 #142594 (comment)
1 parent 0e45731 commit cf4a828

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -289,34 +289,12 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
289289
if (hasVectorValue(Def))
290290
return Data.VPV2Vector[Def];
291291

292-
auto GetBroadcastInstrs = [this, Def](Value *V) {
293-
bool SafeToHoist =
294-
!Def->hasDefiningRecipe() ||
295-
VPDT.properlyDominates(Def->getDefiningRecipe()->getParent(),
296-
Plan->getVectorPreheader());
297-
298-
if (VF.isScalar())
299-
return V;
300-
// Place the code for broadcasting invariant variables in the new preheader.
301-
IRBuilder<>::InsertPointGuard Guard(Builder);
302-
if (SafeToHoist) {
303-
BasicBlock *LoopVectorPreHeader =
304-
CFG.VPBB2IRBB[Plan->getVectorPreheader()];
305-
if (LoopVectorPreHeader)
306-
Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator());
307-
}
308-
309-
// Place the code for broadcasting invariant variables in the new preheader.
310-
// Broadcast the scalar into all locations in the vector.
311-
Value *Shuf = Builder.CreateVectorSplat(VF, V, "broadcast");
312-
313-
return Shuf;
314-
};
315-
316292
if (!hasScalarValue(Def, {0})) {
317293
assert(Def->isLiveIn() && "expected a live-in");
318294
Value *IRV = Def->getLiveInIRValue();
319-
Value *B = GetBroadcastInstrs(IRV);
295+
if (VF.isScalar())
296+
return IRV;
297+
Value *B = Builder.CreateVectorSplat(VF, IRV, "broadcast");
320298
set(Def, B);
321299
return B;
322300
}
@@ -361,7 +339,7 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
361339
// insertelements once.
362340
Value *VectorValue = nullptr;
363341
if (IsSingleScalar) {
364-
VectorValue = GetBroadcastInstrs(ScalarValue);
342+
VectorValue = Builder.CreateVectorSplat(VF, ScalarValue, "broadcast");
365343
set(Def, VectorValue);
366344
} else {
367345
// Initialize packing with insertelements to start from undef.

0 commit comments

Comments
 (0)