@@ -9683,15 +9683,16 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9683
9683
// bc.merge.rdx phi nodes, hence it needs to be created unconditionally here
9684
9684
// even for in-loop reductions, until the reduction resume value handling is
9685
9685
// also modeled in VPlan.
9686
- auto *FinalReductionResult = new VPInstruction (
9686
+ VPBuilder::InsertPointGuard Guard (Builder);
9687
+ Builder.setInsertPoint (MiddleVPBB, IP);
9688
+ auto *FinalReductionResult = Builder.createNaryOp (
9687
9689
VPInstruction::ComputeReductionResult, {PhiR, NewExitingVPV}, ExitDL);
9688
9690
// Update all users outside the vector region.
9689
9691
OrigExitingVPV->replaceUsesWithIf (
9690
- FinalReductionResult, [](VPUser &User, unsigned ) {
9692
+ FinalReductionResult, [FinalReductionResult ](VPUser &User, unsigned ) {
9691
9693
auto *Parent = cast<VPRecipeBase>(&User)->getParent ();
9692
- return Parent && !Parent->getParent ();
9694
+ return FinalReductionResult != &User && !Parent->getParent ();
9693
9695
});
9694
- FinalReductionResult->insertBefore (*MiddleVPBB, IP);
9695
9696
9696
9697
// Adjust AnyOf reductions; replace the reduction phi for the selected value
9697
9698
// with a boolean reduction phi node to check if the condition is true in
@@ -9713,7 +9714,6 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9713
9714
if (CmpR->getOperand (I) == PhiR)
9714
9715
CmpR->setOperand (I, PhiR->getStartValue ());
9715
9716
}
9716
- VPBuilder::InsertPointGuard Guard (Builder);
9717
9717
Builder.setInsertPoint (Select);
9718
9718
9719
9719
// If the true value of the select is the reduction phi, the new value is
0 commit comments