Skip to content

Commit 69c8231

Browse files
committed
[LV] Move condition to VPPartialReductionRecipe::execute
This means that VPExpressions will now be constructed for VPPartialReductionRecipe's when the loop has tail-folding predication. Note that control-flow (if/else) predication is not yet handled for partial reductions, because of the way partial reductions are recognised and built up.
1 parent d79088a commit 69c8231

File tree

6 files changed

+345
-661
lines changed

6 files changed

+345
-661
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8171,15 +8171,8 @@ VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction,
81718171
}
81728172

81738173
VPValue *Cond = nullptr;
8174-
if (CM.blockNeedsPredicationForAnyReason(Reduction->getParent())) {
8175-
assert((ReductionOpcode == Instruction::Add ||
8176-
ReductionOpcode == Instruction::Sub) &&
8177-
"Expected an ADD or SUB operation for predicated partial "
8178-
"reductions (because the neutral element in the mask is zero)!");
8174+
if (CM.blockNeedsPredicationForAnyReason(Reduction->getParent()))
81798175
Cond = getBlockInMask(Builder.getInsertBlock());
8180-
VPValue *Zero = Plan.getConstantInt(Reduction->getType(), 0);
8181-
BinOp = Builder.createSelect(Cond, BinOp, Zero, Reduction->getDebugLoc());
8182-
}
81838176
return new VPPartialReductionRecipe(ReductionOpcode, Accumulator, BinOp, Cond,
81848177
ScaleFactor, Reduction);
81858178
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,18 @@ void VPPartialReductionRecipe::execute(VPTransformState &State) {
395395
assert(getOpcode() == Instruction::Add &&
396396
"Unhandled partial reduction opcode");
397397

398-
Value *BinOpVal = State.get(getOperand(1));
399-
Value *PhiVal = State.get(getOperand(0));
398+
Value *BinOpVal = State.get(getVecOp());
399+
Value *PhiVal = State.get(getChainOp());
400400
assert(PhiVal && BinOpVal && "Phi and Mul must be set");
401401

402402
Type *RetTy = PhiVal->getType();
403403

404+
if (isConditional()) {
405+
Value *Cond = State.get(getCondOp());
406+
Value *Zero = ConstantInt::get(BinOpVal->getType(), 0);
407+
BinOpVal = Builder.CreateSelect(Cond, BinOpVal, Zero);
408+
}
409+
404410
CallInst *V =
405411
Builder.CreateIntrinsic(RetTy, Intrinsic::vector_partial_reduce_add,
406412
{PhiVal, BinOpVal}, nullptr, "partial.reduce");

0 commit comments

Comments
 (0)