Skip to content

Commit c04d219

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 b58b38e commit c04d219

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
@@ -8226,15 +8226,8 @@ VPRecipeBuilder::tryToCreatePartialReduction(VPInstruction *Reduction,
82268226
}
82278227

82288228
VPValue *Cond = nullptr;
8229-
if (CM.blockNeedsPredicationForAnyReason(ReductionI->getParent())) {
8230-
assert((ReductionOpcode == Instruction::Add ||
8231-
ReductionOpcode == Instruction::Sub) &&
8232-
"Expected an ADD or SUB operation for predicated partial "
8233-
"reductions (because the neutral element in the mask is zero)!");
8229+
if (CM.blockNeedsPredicationForAnyReason(ReductionI->getParent()))
82348230
Cond = getBlockInMask(Builder.getInsertBlock());
8235-
VPValue *Zero = Plan.getConstantInt(ReductionI->getType(), 0);
8236-
BinOp = Builder.createSelect(Cond, BinOp, Zero, Reduction->getDebugLoc());
8237-
}
82388231
return new VPPartialReductionRecipe(ReductionOpcode, Accumulator, BinOp, Cond,
82398232
ScaleFactor, ReductionI);
82408233
}

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)