Skip to content

Commit 64954f6

Browse files
Add assert statement to ensure the PR is an Add or Sub
This is because the neutral element in the mask is zero.
1 parent 055d227 commit 64954f6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8918,14 +8918,19 @@ VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction,
89188918
isa<VPPartialReductionRecipe>(BinOpRecipe))
89198919
std::swap(BinOp, Accumulator);
89208920

8921+
unsigned ReductionOpcode = Reduction->getOpcode();
89218922
if (CM.blockNeedsPredicationForAnyReason(Reduction->getParent())) {
8923+
assert((ReductionOpcode == Instruction::Add ||
8924+
ReductionOpcode == Instruction::Sub) &&
8925+
"Expected an ADD or SUB operation for predicated partial "
8926+
"reductions (because the neutral element in the mask is zero)!");
89228927
VPValue *Mask = getBlockInMask(Reduction->getParent());
89238928
VPValue *Zero =
89248929
Plan.getOrAddLiveIn(ConstantInt::get(Reduction->getType(), 0));
89258930
BinOp = Builder.createSelect(Mask, BinOp, Zero, Reduction->getDebugLoc());
89268931
}
8927-
return new VPPartialReductionRecipe(Reduction->getOpcode(), BinOp,
8928-
Accumulator, Reduction);
8932+
return new VPPartialReductionRecipe(ReductionOpcode, BinOp, Accumulator,
8933+
Reduction);
89298934
}
89308935

89318936
void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,

0 commit comments

Comments
 (0)