@@ -575,6 +575,29 @@ Value *VPInstruction::generate(VPTransformState &State) {
575
575
Builder.GetInsertBlock ()->getTerminator ()->eraseFromParent ();
576
576
return CondBr;
577
577
}
578
+ case VPInstruction::ComputeFindLastIVResult: {
579
+ // FIXME: The cross-recipe dependency on VPReductionPHIRecipe is temporary
580
+ // and will be removed by breaking up the recipe further.
581
+ auto *PhiR = cast<VPReductionPHIRecipe>(getOperand (0 ));
582
+ // Get its reduction variable descriptor.
583
+ const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
584
+ RecurKind RK = RdxDesc.getRecurrenceKind ();
585
+ assert (RecurrenceDescriptor::isFindLastIVRecurrenceKind (RK) &&
586
+ " Unexpected reduction kind" );
587
+ assert (!PhiR->isInLoop () &&
588
+ " In-loop FindLastIV reduction is not supported yet" );
589
+
590
+ // The recipe's operands are the reduction phi, followed by one operand for
591
+ // each part of the reduction.
592
+ unsigned UF = getNumOperands () - 1 ;
593
+ Value *ReducedPartRdx = State.get (getOperand (1 ));
594
+ for (unsigned Part = 1 ; Part < UF; ++Part) {
595
+ ReducedPartRdx = createMinMaxOp (Builder, RecurKind::SMax, ReducedPartRdx,
596
+ State.get (getOperand (1 + Part)));
597
+ }
598
+
599
+ return createFindLastIVReduction (Builder, ReducedPartRdx, RdxDesc);
600
+ }
578
601
case VPInstruction::ComputeReductionResult: {
579
602
// FIXME: The cross-recipe dependency on VPReductionPHIRecipe is temporary
580
603
// and will be removed by breaking up the recipe further.
@@ -584,6 +607,8 @@ Value *VPInstruction::generate(VPTransformState &State) {
584
607
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
585
608
586
609
RecurKind RK = RdxDesc.getRecurrenceKind ();
610
+ assert (!RecurrenceDescriptor::isFindLastIVRecurrenceKind (RK) &&
611
+ " should be handled by ComputeFindLastIVResult" );
587
612
588
613
Type *PhiTy = OrigPhi->getType ();
589
614
// The recipe's operands are the reduction phi, followed by one operand for
@@ -619,9 +644,6 @@ Value *VPInstruction::generate(VPTransformState &State) {
619
644
if (Op != Instruction::ICmp && Op != Instruction::FCmp)
620
645
ReducedPartRdx = Builder.CreateBinOp (
621
646
(Instruction::BinaryOps)Op, RdxPart, ReducedPartRdx, " bin.rdx" );
622
- else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind (RK))
623
- ReducedPartRdx =
624
- createMinMaxOp (Builder, RecurKind::SMax, ReducedPartRdx, RdxPart);
625
647
else
626
648
ReducedPartRdx = createMinMaxOp (Builder, RK, ReducedPartRdx, RdxPart);
627
649
}
@@ -630,8 +652,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
630
652
// Create the reduction after the loop. Note that inloop reductions create
631
653
// the target reduction in the loop using a Reduction recipe.
632
654
if ((State.VF .isVector () ||
633
- RecurrenceDescriptor::isAnyOfRecurrenceKind (RK) ||
634
- RecurrenceDescriptor::isFindLastIVRecurrenceKind (RK)) &&
655
+ RecurrenceDescriptor::isAnyOfRecurrenceKind (RK)) &&
635
656
!PhiR->isInLoop ()) {
636
657
// TODO: Support in-order reductions based on the recurrence descriptor.
637
658
// All ops in the reduction inherit fast-math-flags from the recurrence
@@ -642,9 +663,6 @@ Value *VPInstruction::generate(VPTransformState &State) {
642
663
if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RK))
643
664
ReducedPartRdx =
644
665
createAnyOfReduction (Builder, ReducedPartRdx, RdxDesc, OrigPhi);
645
- else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind (RK))
646
- ReducedPartRdx =
647
- createFindLastIVReduction (Builder, ReducedPartRdx, RdxDesc);
648
666
else
649
667
ReducedPartRdx = createSimpleReduction (Builder, ReducedPartRdx, RK);
650
668
@@ -742,6 +760,7 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
742
760
743
761
bool VPInstruction::isVectorToScalar () const {
744
762
return getOpcode () == VPInstruction::ExtractFromEnd ||
763
+ getOpcode () == VPInstruction::ComputeFindLastIVResult ||
745
764
getOpcode () == VPInstruction::ComputeReductionResult ||
746
765
getOpcode () == VPInstruction::AnyOf;
747
766
}
@@ -913,6 +932,9 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
913
932
case VPInstruction::ExtractFromEnd:
914
933
O << " extract-from-end" ;
915
934
break ;
935
+ case VPInstruction::ComputeFindLastIVResult:
936
+ O << " compute-find-last-iv-result" ;
937
+ break ;
916
938
case VPInstruction::ComputeReductionResult:
917
939
O << " compute-reduction-result" ;
918
940
break ;
0 commit comments