Skip to content

Commit f337525

Browse files
[SLP] Compute a shuffle mask for SK_Broadcast shuffle (#85327)
This is the first of a couple of small patches to compute shuffle masks for the couple of cases where we call getShuffleCost without one. My goal is to add an invariant that all calls to getShuffleCost for fixed length vectors have a mask. --------- Co-authored-by: Alexey Bataev <[email protected]>
1 parent accf0af commit f337525

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7691,16 +7691,22 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
76917691
bool NeedShuffle =
76927692
count(VL, *It) > 1 &&
76937693
(VL.front() != *It || !all_of(VL.drop_front(), UndefValue::classof));
7694+
if (!NeedShuffle)
7695+
return TTI.getVectorInstrCost(Instruction::InsertElement, VecTy,
7696+
CostKind, std::distance(VL.begin(), It),
7697+
PoisonValue::get(VecTy), *It);
7698+
7699+
SmallVector<int> ShuffleMask(VL.size(), PoisonMaskElem);
7700+
transform(VL, ShuffleMask.begin(), [](Value *V) {
7701+
return isa<PoisonValue>(V) ? PoisonMaskElem : 0;
7702+
});
76947703
InstructionCost InsertCost = TTI.getVectorInstrCost(
7695-
Instruction::InsertElement, VecTy, CostKind,
7696-
NeedShuffle ? 0 : std::distance(VL.begin(), It),
7704+
Instruction::InsertElement, VecTy, CostKind, 0,
76977705
PoisonValue::get(VecTy), *It);
76987706
return InsertCost +
7699-
(NeedShuffle ? TTI.getShuffleCost(
7700-
TargetTransformInfo::SK_Broadcast, VecTy,
7701-
/*Mask=*/std::nullopt, CostKind, /*Index=*/0,
7702-
/*SubTp=*/nullptr, /*Args=*/*It)
7703-
: TTI::TCC_Free);
7707+
TTI.getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy,
7708+
ShuffleMask, CostKind, /*Index=*/0,
7709+
/*SubTp=*/nullptr, /*Args=*/*It);
77047710
}
77057711
return GatherCost +
77067712
(all_of(Gathers, UndefValue::classof)

0 commit comments

Comments
 (0)