Skip to content

Commit 414590b

Browse files
committed
[VPlan] Infer result type for ComptueReductionResult in ::execute (NFC).
Remove explicit use of underlying instruction to get type.
1 parent 0583297 commit 414590b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -647,15 +647,14 @@ Value *VPInstruction::generate(VPTransformState &State) {
647647
// FIXME: The cross-recipe dependency on VPReductionPHIRecipe is temporary
648648
// and will be removed by breaking up the recipe further.
649649
auto *PhiR = cast<VPReductionPHIRecipe>(getOperand(0));
650-
auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue());
651650
// Get its reduction variable descriptor.
652651
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
653652

654653
RecurKind RK = RdxDesc.getRecurrenceKind();
655654
assert(!RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK) &&
656655
"should be handled by ComputeFindLastIVResult");
657656

658-
Type *PhiTy = OrigPhi->getType();
657+
Type *ResultTy = State.TypeAnalysis.inferScalarType(this);
659658
// The recipe's operands are the reduction phi, followed by one operand for
660659
// each part of the reduction.
661660
unsigned UF = getNumOperands() - 1;
@@ -671,7 +670,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
671670
// then extend the loop exit value to enable InstCombine to evaluate the
672671
// entire expression in the smaller type.
673672
// TODO: Handle this in truncateToMinBW.
674-
if (State.VF.isVector() && PhiTy != RdxDesc.getRecurrenceType()) {
673+
if (State.VF.isVector() && ResultTy != RdxDesc.getRecurrenceType()) {
675674
Type *RdxVecTy = VectorType::get(RdxDesc.getRecurrenceType(), State.VF);
676675
for (unsigned Part = 0; Part < UF; ++Part)
677676
RdxParts[Part] = Builder.CreateTrunc(RdxParts[Part], RdxVecTy);
@@ -703,10 +702,10 @@ Value *VPInstruction::generate(VPTransformState &State) {
703702

704703
// If the reduction can be performed in a smaller type, we need to extend
705704
// the reduction to the wider type before we branch to the original loop.
706-
if (PhiTy != RdxDesc.getRecurrenceType())
705+
if (ResultTy != RdxDesc.getRecurrenceType())
707706
ReducedPartRdx = RdxDesc.isSigned()
708-
? Builder.CreateSExt(ReducedPartRdx, PhiTy)
709-
: Builder.CreateZExt(ReducedPartRdx, PhiTy);
707+
? Builder.CreateSExt(ReducedPartRdx, ResultTy)
708+
: Builder.CreateZExt(ReducedPartRdx, ResultTy);
710709
}
711710

712711
return ReducedPartRdx;

0 commit comments

Comments
 (0)