@@ -3051,8 +3051,9 @@ PHINode *InnerLoopVectorizer::createInductionResumeValue(
3051
3051
}
3052
3052
3053
3053
// Create phi nodes to merge from the backedge-taken check block.
3054
- PHINode *BCResumeVal = PHINode::Create(OrigPhi->getType(), 3, "bc.resume.val",
3055
- LoopScalarPreHeader->getFirstNonPHI());
3054
+ PHINode *BCResumeVal =
3055
+ PHINode::Create(OrigPhi->getType(), 3, "bc.resume.val",
3056
+ LoopScalarPreHeader->getTerminator()->getIterator());
3056
3057
// Copy original phi DL over to the new one.
3057
3058
BCResumeVal->setDebugLoc(OrigPhi->getDebugLoc());
3058
3059
@@ -7450,6 +7451,7 @@ static void createAndCollectMergePhiForReduction(
7450
7451
auto *PhiR = cast<VPReductionPHIRecipe>(RedResult->getOperand(0));
7451
7452
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
7452
7453
7454
+ TrackingVH<Value> ReductionStartValue = RdxDesc.getRecurrenceStartValue();
7453
7455
Value *FinalValue =
7454
7456
State.get(RedResult, VPIteration(State.UF - 1, VPLane::getFirstLane()));
7455
7457
auto *ResumePhi =
@@ -7474,7 +7476,7 @@ static void createAndCollectMergePhiForReduction(
7474
7476
BCBlockPhi->addIncoming(ResumePhi->getIncomingValueForBlock(Incoming),
7475
7477
Incoming);
7476
7478
else
7477
- BCBlockPhi->addIncoming(RdxDesc.getRecurrenceStartValue() , Incoming);
7479
+ BCBlockPhi->addIncoming(ReductionStartValue , Incoming);
7478
7480
}
7479
7481
7480
7482
auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue());
@@ -7767,10 +7769,11 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton(
7767
7769
7768
7770
// Now, compare the remaining count and if there aren't enough iterations to
7769
7771
// execute the vectorized epilogue skip to the scalar part.
7770
- LoopVectorPreHeader->setName("vec.epilog.ph");
7771
- BasicBlock *VecEpilogueIterationCountCheck =
7772
- SplitBlock(LoopVectorPreHeader, LoopVectorPreHeader->begin(), DT, LI,
7773
- nullptr, "vec.epilog.iter.check", true);
7772
+ BasicBlock *VecEpilogueIterationCountCheck = LoopVectorPreHeader;
7773
+ VecEpilogueIterationCountCheck->setName("vec.epilog.iter.check");
7774
+ LoopVectorPreHeader =
7775
+ SplitBlock(LoopVectorPreHeader, LoopVectorPreHeader->getTerminator(), DT,
7776
+ LI, nullptr, "vec.epilog.ph");
7774
7777
emitMinimumVectorEpilogueIterCountCheck(LoopScalarPreHeader,
7775
7778
VecEpilogueIterationCountCheck);
7776
7779
@@ -8893,10 +8896,6 @@ VPlanPtr LoopVectorizationPlanner::buildVPlan(VFRange &Range) {
8893
8896
// A ComputeReductionResult recipe is added to the middle block, also for
8894
8897
// in-loop reductions which compute their result in-loop, because generating
8895
8898
// the subsequent bc.merge.rdx phi is driven by ComputeReductionResult recipes.
8896
- //
8897
- // Adjust AnyOf reductions; replace the reduction phi for the selected value
8898
- // with a boolean reduction phi node to check if the condition is true in any
8899
- // iteration. The final value is selected by the final ComputeReductionResult.
8900
8899
void LoopVectorizationPlanner::adjustRecipesForReductions(
8901
8900
VPBasicBlock *LatchVPBB, VPlanPtr &Plan, VPRecipeBuilder &RecipeBuilder,
8902
8901
ElementCount MinVF) {
@@ -9071,41 +9070,6 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9071
9070
continue;
9072
9071
9073
9072
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
9074
- // Adjust AnyOf reductions; replace the reduction phi for the selected value
9075
- // with a boolean reduction phi node to check if the condition is true in
9076
- // any iteration. The final value is selected by the final
9077
- // ComputeReductionResult.
9078
- if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
9079
- RdxDesc.getRecurrenceKind())) {
9080
- auto *Select = cast<VPRecipeBase>(*find_if(PhiR->users(), [](VPUser *U) {
9081
- return isa<VPWidenSelectRecipe>(U) ||
9082
- (isa<VPReplicateRecipe>(U) &&
9083
- cast<VPReplicateRecipe>(U)->getUnderlyingInstr()->getOpcode() ==
9084
- Instruction::Select);
9085
- }));
9086
- VPValue *Cmp = Select->getOperand(0);
9087
- // If the compare is checking the reduction PHI node, adjust it to check
9088
- // the start value.
9089
- if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe()) {
9090
- for (unsigned I = 0; I != CmpR->getNumOperands(); ++I)
9091
- if (CmpR->getOperand(I) == PhiR)
9092
- CmpR->setOperand(I, PhiR->getStartValue());
9093
- }
9094
- VPBuilder::InsertPointGuard Guard(Builder);
9095
- Builder.setInsertPoint(Select);
9096
-
9097
- // If the true value of the select is the reduction phi, the new value is
9098
- // selected if the negated condition is true in any iteration.
9099
- if (Select->getOperand(1) == PhiR)
9100
- Cmp = Builder.createNot(Cmp);
9101
- VPValue *Or = Builder.createOr(PhiR, Cmp);
9102
- Select->getVPSingleValue()->replaceAllUsesWith(Or);
9103
-
9104
- // Convert the reduction phi to operate on bools.
9105
- PhiR->setOperand(0, Plan->getOrAddLiveIn(ConstantInt::getFalse(
9106
- OrigLoop->getHeader()->getContext())));
9107
- }
9108
-
9109
9073
// If tail is folded by masking, introduce selects between the phi
9110
9074
// and the live-out instruction of each reduction, at the beginning of the
9111
9075
// dedicated latch block.
@@ -9138,9 +9102,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9138
9102
// then extend the loop exit value to enable InstCombine to evaluate the
9139
9103
// entire expression in the smaller type.
9140
9104
Type *PhiTy = PhiR->getStartValue()->getLiveInIRValue()->getType();
9141
- if (MinVF.isVector() && PhiTy != RdxDesc.getRecurrenceType() &&
9142
- !RecurrenceDescriptor::isAnyOfRecurrenceKind(
9143
- RdxDesc.getRecurrenceKind())) {
9105
+ if (MinVF.isVector() && PhiTy != RdxDesc.getRecurrenceType()) {
9144
9106
assert(!PhiR->isInLoop() && "Unexpected truncated inloop reduction!");
9145
9107
Type *RdxTy = RdxDesc.getRecurrenceType();
9146
9108
auto *Trunc =
@@ -10181,19 +10143,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10181
10143
Value *ResumeV = nullptr;
10182
10144
// TODO: Move setting of resume values to prepareToExecute.
10183
10145
if (auto *ReductionPhi = dyn_cast<VPReductionPHIRecipe>(&R)) {
10184
- const RecurrenceDescriptor &RdxDesc =
10185
- ReductionPhi->getRecurrenceDescriptor();
10186
- RecurKind RK = RdxDesc.getRecurrenceKind();
10187
- ResumeV = ReductionResumeValues.find(&RdxDesc)->second;
10188
- if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK)) {
10189
- // VPReductionPHIRecipes for AnyOf reductions expect a boolean as
10190
- // start value; compare the final value from the main vector loop
10191
- // to the start value.
10192
- IRBuilder<> Builder(
10193
- cast<Instruction>(ResumeV)->getParent()->getFirstNonPHI());
10194
- ResumeV = Builder.CreateICmpNE(ResumeV,
10195
- RdxDesc.getRecurrenceStartValue());
10196
- }
10146
+ ResumeV = ReductionResumeValues
10147
+ .find(&ReductionPhi->getRecurrenceDescriptor())
10148
+ ->second;
10197
10149
} else {
10198
10150
// Create induction resume values for both widened pointer and
10199
10151
// integer/fp inductions and update the start value of the induction
0 commit comments