Skip to content

Commit 008df3c

Browse files
authored
[LV] Check isPredInst instead of isScalarWithPred in uniform analysis. (#98892)
Any instruction marked as uniform will result in a uniform VPReplicateRecipe. If it requires predication, it will be placed in a replicate region, even if isScalarWithPredication returns false. Check isPredicatedInst instead of isScalarWithPredication to avoid generating uniform VPReplicateRecipes placed inside a replicate region. This fixes an assertion when using scalable VFs. Fixes #80416. Fixes #94328. Fixes #99625. PR: #98892
1 parent 098bd84 commit 008df3c

File tree

3 files changed

+309
-8
lines changed

3 files changed

+309
-8
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,19 +3914,19 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) {
39143914
SetVector<Instruction *> Worklist;
39153915

39163916
// Add uniform instructions demanding lane 0 to the worklist. Instructions
3917-
// that are scalar with predication must not be considered uniform after
3917+
// that require predication must not be considered uniform after
39183918
// vectorization, because that would create an erroneous replicating region
39193919
// where only a single instance out of VF should be formed.
3920-
// TODO: optimize such seldom cases if found important, see PR40816.
39213920
auto addToWorklistIfAllowed = [&](Instruction *I) -> void {
39223921
if (isOutOfScope(I)) {
39233922
LLVM_DEBUG(dbgs() << "LV: Found not uniform due to scope: "
39243923
<< *I << "\n");
39253924
return;
39263925
}
3927-
if (isScalarWithPredication(I, VF)) {
3928-
LLVM_DEBUG(dbgs() << "LV: Found not uniform being ScalarWithPredication: "
3929-
<< *I << "\n");
3926+
if (isPredicatedInst(I)) {
3927+
LLVM_DEBUG(
3928+
dbgs() << "LV: Found not uniform due to requiring predication: " << *I
3929+
<< "\n");
39303930
return;
39313931
}
39323932
LLVM_DEBUG(dbgs() << "LV: Found uniform instruction: " << *I << "\n");
@@ -9516,6 +9516,8 @@ void VPInterleaveRecipe::execute(VPTransformState &State) {
95169516
void VPReplicateRecipe::execute(VPTransformState &State) {
95179517
Instruction *UI = getUnderlyingInstr();
95189518
if (State.Instance) { // Generate a single instance.
9519+
assert((State.VF.isScalar() || !isUniform()) &&
9520+
"uniform recipe shouldn't be predicated");
95199521
assert(!State.VF.isScalable() && "Can't scalarize a scalable vector");
95209522
State.ILV->scalarizeInstruction(UI, this, *State.Instance, State);
95219523
// Insert scalar instance packing it into a vector.

0 commit comments

Comments
 (0)