@@ -9294,41 +9294,6 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9294
9294
continue ;
9295
9295
9296
9296
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9297
- // Adjust AnyOf reductions; replace the reduction phi for the selected value
9298
- // with a boolean reduction phi node to check if the condition is true in
9299
- // any iteration. The final value is selected by the final
9300
- // ComputeReductionResult.
9301
- if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
9302
- RdxDesc.getRecurrenceKind ())) {
9303
- auto *Select = cast<VPRecipeBase>(*find_if (PhiR->users (), [](VPUser *U) {
9304
- return isa<VPWidenSelectRecipe>(U) ||
9305
- (isa<VPReplicateRecipe>(U) &&
9306
- cast<VPReplicateRecipe>(U)->getUnderlyingInstr ()->getOpcode () ==
9307
- Instruction::Select);
9308
- }));
9309
- VPValue *Cmp = Select->getOperand (0 );
9310
- // If the compare is checking the reduction PHI node, adjust it to check
9311
- // the start value.
9312
- if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe ()) {
9313
- for (unsigned I = 0 ; I != CmpR->getNumOperands (); ++I)
9314
- if (CmpR->getOperand (I) == PhiR)
9315
- CmpR->setOperand (I, PhiR->getStartValue ());
9316
- }
9317
- VPBuilder::InsertPointGuard Guard (Builder);
9318
- Builder.setInsertPoint (Select);
9319
-
9320
- // If the true value of the select is the reduction phi, the new value is
9321
- // selected if the negated condition is true in any iteration.
9322
- if (Select->getOperand (1 ) == PhiR)
9323
- Cmp = Builder.createNot (Cmp);
9324
- VPValue *Or = Builder.createOr (PhiR, Cmp);
9325
- Select->getVPSingleValue ()->replaceAllUsesWith (Or);
9326
-
9327
- // Convert the reduction phi to operate on bools.
9328
- PhiR->setOperand (0 , Plan->getOrAddLiveIn (ConstantInt::getFalse (
9329
- OrigLoop->getHeader ()->getContext ())));
9330
- }
9331
-
9332
9297
// If tail is folded by masking, introduce selects between the phi
9333
9298
// and the live-out instruction of each reduction, at the beginning of the
9334
9299
// dedicated latch block.
@@ -9401,6 +9366,41 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9401
9366
return match (&User, m_Binary<VPInstruction::ExtractFromEnd>(m_VPValue (),
9402
9367
m_VPValue ()));
9403
9368
});
9369
+
9370
+ // Adjust AnyOf reductions; replace the reduction phi for the selected value
9371
+ // with a boolean reduction phi node to check if the condition is true in
9372
+ // any iteration. The final value is selected by the final
9373
+ // ComputeReductionResult.
9374
+ if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
9375
+ RdxDesc.getRecurrenceKind ())) {
9376
+ auto *Select = cast<VPRecipeBase>(*find_if (PhiR->users (), [](VPUser *U) {
9377
+ return isa<VPWidenSelectRecipe>(U) ||
9378
+ (isa<VPReplicateRecipe>(U) &&
9379
+ cast<VPReplicateRecipe>(U)->getUnderlyingInstr ()->getOpcode () ==
9380
+ Instruction::Select);
9381
+ }));
9382
+ VPValue *Cmp = Select->getOperand (0 );
9383
+ // If the compare is checking the reduction PHI node, adjust it to check
9384
+ // the start value.
9385
+ if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe ()) {
9386
+ for (unsigned I = 0 ; I != CmpR->getNumOperands (); ++I)
9387
+ if (CmpR->getOperand (I) == PhiR)
9388
+ CmpR->setOperand (I, PhiR->getStartValue ());
9389
+ }
9390
+ VPBuilder::InsertPointGuard Guard (Builder);
9391
+ Builder.setInsertPoint (Select);
9392
+
9393
+ // If the true value of the select is the reduction phi, the new value is
9394
+ // selected if the negated condition is true in any iteration.
9395
+ if (Select->getOperand (1 ) == PhiR)
9396
+ Cmp = Builder.createNot (Cmp);
9397
+ VPValue *Or = Builder.createOr (PhiR, Cmp);
9398
+ Select->getVPSingleValue ()->replaceAllUsesWith (Or);
9399
+
9400
+ // Convert the reduction phi to operate on bools.
9401
+ PhiR->setOperand (0 , Plan->getOrAddLiveIn (ConstantInt::getFalse (
9402
+ OrigLoop->getHeader ()->getContext ())));
9403
+ }
9404
9404
}
9405
9405
9406
9406
VPlanTransforms::clearReductionWrapFlags (*Plan);
0 commit comments