Skip to content

Commit 5431f7e

Browse files
committed
[VPlan] Add ReductionStartVector VPInstruction.
Add a new VPInstruction::ReductionStartVector opcode to create the start values for wide reductions. This more accurately models the start value creation in VPlan and simplifies VPReductionPHIRecipe::execute.
1 parent eccfced commit 5431f7e

14 files changed

+121
-78
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7509,8 +7509,11 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
75097509
cast<VPReductionPHIRecipe>(EpiRedResult->getOperand(0));
75107510
const RecurrenceDescriptor &RdxDesc =
75117511
EpiRedHeaderPhi->getRecurrenceDescriptor();
7512-
Value *MainResumeValue =
7513-
EpiRedHeaderPhi->getStartValue()->getUnderlyingValue();
7512+
Value *MainResumeValue;
7513+
if (auto *VPI = dyn_cast<VPInstruction>(EpiRedHeaderPhi->getStartValue()))
7514+
MainResumeValue = VPI->getOperand(0)->getUnderlyingValue();
7515+
else
7516+
MainResumeValue = EpiRedHeaderPhi->getStartValue()->getUnderlyingValue();
75147517
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
75157518
RdxDesc.getRecurrenceKind())) {
75167519
Value *StartV = EpiRedResult->getOperand(1)->getLiveInIRValue();
@@ -8570,6 +8573,7 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
85708573
// If the PHI is used by a partial reduction, set the scale factor.
85718574
unsigned ScaleFactor =
85728575
getScalingForReduction(RdxDesc.getLoopExitInstr()).value_or(1);
8576+
85738577
PhiRecipe = new VPReductionPHIRecipe(
85748578
Phi, RdxDesc, *StartV, CM.isInLoopReduction(Phi),
85758579
CM.useOrderedReductions(RdxDesc), ScaleFactor);
@@ -9457,7 +9461,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
94579461
continue;
94589462

94599463
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
9460-
Type *PhiTy = PhiR->getOperand(0)->getLiveInIRValue()->getType();
9464+
Type *PhiTy = PhiR->getUnderlyingValue()->getType();
94619465
// If tail is folded by masking, introduce selects between the phi
94629466
// and the users outside the vector region of each reduction, at the
94639467
// beginning of the dedicated latch block.
@@ -9601,6 +9605,27 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
96019605
// start value.
96029606
PhiR->setOperand(0, Plan->getOrAddLiveIn(RdxDesc.getSentinelValue()));
96039607
}
9608+
RecurKind RK = RdxDesc.getRecurrenceKind();
9609+
if (PhiR->isOrdered() || PhiR->isInLoop() ||
9610+
(!RecurrenceDescriptor::isAnyOfRecurrenceKind(RK) &&
9611+
!RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK) &&
9612+
!RecurrenceDescriptor::isMinMaxRecurrenceKind(RK))) {
9613+
VPBuilder PHBuilder(Plan->getVectorPreheader());
9614+
VPValue *Iden = Plan->getOrAddLiveIn(
9615+
getRecurrenceIdentity(RK, PhiTy, RdxDesc.getFastMathFlags()));
9616+
// If the PHI is used by a partial reduction, set the scale factor.
9617+
unsigned ScaleFactor =
9618+
RecipeBuilder.getScalingForReduction(RdxDesc.getLoopExitInstr())
9619+
.value_or(1);
9620+
Type *I32Ty = IntegerType::getInt32Ty(PhiTy->getContext());
9621+
auto *ScalarFactorVPV =
9622+
Plan->getOrAddLiveIn(ConstantInt::get(I32Ty, ScaleFactor));
9623+
VPValue *StartV =
9624+
PHBuilder.createNaryOp(VPInstruction::ReductionStartVector,
9625+
{PhiR->getStartValue(), Iden, ScalarFactorVPV},
9626+
RdxDesc.getFastMathFlags());
9627+
PhiR->setOperand(0, StartV);
9628+
}
96049629
}
96059630
for (VPRecipeBase *R : ToDelete)
96069631
R->eraseFromParent();
@@ -10125,6 +10150,12 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
1012510150
}
1012610151
assert(ResumeV && "Must have a resume value");
1012710152
VPValue *StartVal = Plan.getOrAddLiveIn(ResumeV);
10153+
if (auto *PhiR = dyn_cast<VPReductionPHIRecipe>(&R)) {
10154+
if (auto *VPI = dyn_cast<VPInstruction>(PhiR->getStartValue())) {
10155+
VPI->setOperand(0, StartVal);
10156+
continue;
10157+
}
10158+
}
1012810159
cast<VPHeaderPHIRecipe>(&R)->setStartValue(StartVal);
1012910160
}
1013010161

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,10 @@ class VPInstruction : public VPRecipeWithIRFlags,
907907
BranchOnCount,
908908
BranchOnCond,
909909
Broadcast,
910+
/// Start vector for reductions with 3 operands: the original start value,
911+
/// the identity value for the reduction and an integer indicating the
912+
/// scaling factor.
913+
ReductionStartVector,
910914
ComputeAnyOfResult,
911915
ComputeFindLastIVResult,
912916
ComputeReductionResult,
@@ -2226,13 +2230,6 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe,
22262230

22272231
/// Returns true, if the phi is part of an in-loop reduction.
22282232
bool isInLoop() const { return IsInLoop; }
2229-
2230-
/// Returns true if the recipe only uses the first lane of operand \p Op.
2231-
bool onlyFirstLaneUsed(const VPValue *Op) const override {
2232-
assert(is_contained(operands(), Op) &&
2233-
"Op must be an operand of the recipe");
2234-
return Op == getStartValue();
2235-
}
22362233
};
22372234

22382235
/// A recipe for vectorizing a phi-node as a sequence of mask-based select

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
8787
inferScalarType(R->getOperand(1)) &&
8888
"different types inferred for different operands");
8989
return IntegerType::get(Ctx, 1);
90+
case VPInstruction::ReductionStartVector:
91+
return inferScalarType(R->getOperand(0));
9092
case VPInstruction::ComputeAnyOfResult:
9193
return inferScalarType(R->getOperand(1));
9294
case VPInstruction::ComputeFindLastIVResult:

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,20 @@ Value *VPInstruction::generate(VPTransformState &State) {
604604
return Builder.CreateVectorSplat(
605605
State.VF, State.get(getOperand(0), /*IsScalar*/ true), "broadcast");
606606
}
607+
case VPInstruction::ReductionStartVector: {
608+
if (State.VF.isScalar())
609+
return State.get(getOperand(0), true);
610+
IRBuilderBase::FastMathFlagGuard FMFG(Builder);
611+
Builder.setFastMathFlags(getFastMathFlags());
612+
// If this start vector is scaled then it should produce a vector with fewer
613+
// elements than the VF.
614+
ElementCount VF = State.VF.divideCoefficientBy(
615+
cast<ConstantInt>(getOperand(2)->getLiveInIRValue())->getZExtValue());
616+
auto *Iden = Builder.CreateVectorSplat(VF, State.get(getOperand(1), true));
617+
Constant *Zero = Builder.getInt32(0);
618+
return Builder.CreateInsertElement(Iden, State.get(getOperand(0), true),
619+
Zero);
620+
}
607621
case VPInstruction::ComputeAnyOfResult: {
608622
// FIXME: The cross-recipe dependency on VPReductionPHIRecipe is temporary
609623
// and will be removed by breaking up the recipe further.
@@ -882,6 +896,7 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
882896
case VPInstruction::PtrAdd:
883897
case VPInstruction::WideIVStep:
884898
case VPInstruction::StepVector:
899+
case VPInstruction::ReductionStartVector:
885900
return false;
886901
default:
887902
return true;
@@ -912,6 +927,7 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
912927
case VPInstruction::CanonicalIVIncrementForPart:
913928
case VPInstruction::BranchOnCount:
914929
case VPInstruction::BranchOnCond:
930+
case VPInstruction::ReductionStartVector:
915931
return true;
916932
case VPInstruction::PtrAdd:
917933
return Op == getOperand(0) || vputils::onlyFirstLaneUsed(this);
@@ -1017,6 +1033,9 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
10171033
case VPInstruction::FirstActiveLane:
10181034
O << "first-active-lane";
10191035
break;
1036+
case VPInstruction::ReductionStartVector:
1037+
O << "reduction-start-vector";
1038+
break;
10201039
default:
10211040
O << Instruction::getOpcodeName(getOpcode());
10221041
}
@@ -1608,6 +1627,7 @@ bool VPIRFlags::flagsValidForOpcode(unsigned Opcode) const {
16081627
Opcode == Instruction::FDiv || Opcode == Instruction::FRem ||
16091628
Opcode == Instruction::FCmp || Opcode == Instruction::Select ||
16101629
Opcode == VPInstruction::WideIVStep ||
1630+
Opcode == VPInstruction::ReductionStartVector ||
16111631
Opcode == VPInstruction::ComputeReductionResult;
16121632
case OperationType::NonNegOp:
16131633
return Opcode == Instruction::ZExt;
@@ -3838,17 +3858,19 @@ void VPFirstOrderRecurrencePHIRecipe::print(raw_ostream &O, const Twine &Indent,
38383858
#endif
38393859

38403860
void VPReductionPHIRecipe::execute(VPTransformState &State) {
3841-
// If this phi is fed by a scaled reduction then it should output a
3842-
// vector with fewer elements than the VF.
3843-
ElementCount VF = State.VF.divideCoefficientBy(VFScaleFactor);
3861+
// Reductions do not have to start at zero. They can start with
3862+
// any loop invariant values.
3863+
VPValue *StartVPV = getStartValue();
38443864

38453865
// In order to support recurrences we need to be able to vectorize Phi nodes.
38463866
// Phi nodes have cycles, so we need to vectorize them in two stages. This is
38473867
// stage #1: We create a new vector PHI node with no incoming edges. We'll use
38483868
// this value when we vectorize all of the instructions that use the PHI.
3849-
auto *ScalarTy = State.TypeAnalysis.inferScalarType(this);
3869+
BasicBlock *VectorPH =
3870+
State.CFG.VPBB2IRBB.at(getParent()->getCFGPredecessor(0));
38503871
bool ScalarPHI = State.VF.isScalar() || IsInLoop;
3851-
Type *VecTy = ScalarPHI ? ScalarTy : VectorType::get(ScalarTy, VF);
3872+
Value *StartV = State.get(StartVPV, ScalarPHI);
3873+
Type *VecTy = StartV->getType();
38523874

38533875
BasicBlock *HeaderBB = State.CFG.PrevBB;
38543876
assert(State.CurrentParentLoop->getHeader() == HeaderBB &&
@@ -3857,49 +3879,7 @@ void VPReductionPHIRecipe::execute(VPTransformState &State) {
38573879
Phi->insertBefore(HeaderBB->getFirstInsertionPt());
38583880
State.set(this, Phi, IsInLoop);
38593881

3860-
BasicBlock *VectorPH =
3861-
State.CFG.VPBB2IRBB.at(getParent()->getCFGPredecessor(0));
3862-
// Create start and identity vector values for the reduction in the preheader.
3863-
// TODO: Introduce recipes in VPlan preheader to create initial values.
3864-
IRBuilderBase::InsertPointGuard IPBuilder(State.Builder);
3865-
State.Builder.SetInsertPoint(VectorPH->getTerminator());
3866-
3867-
// Reductions do not have to start at zero. They can start with
3868-
// any loop invariant values.
3869-
VPValue *StartVPV = getStartValue();
3870-
RecurKind RK = RdxDesc.getRecurrenceKind();
3871-
if (RecurrenceDescriptor::isMinMaxRecurrenceKind(RK) ||
3872-
RecurrenceDescriptor::isAnyOfRecurrenceKind(RK) ||
3873-
RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK)) {
3874-
// [I|F]FindLastIV will use a sentinel value to initialize the reduction
3875-
// phi or the resume value from the main vector loop when vectorizing the
3876-
// epilogue loop. In the exit block, ComputeReductionResult will generate
3877-
// checks to verify if the reduction result is the sentinel value. If the
3878-
// result is the sentinel value, it will be corrected back to the start
3879-
// value.
3880-
// TODO: The sentinel value is not always necessary. When the start value is
3881-
// a constant, and smaller than the start value of the induction variable,
3882-
// the start value can be directly used to initialize the reduction phi.
3883-
Phi->addIncoming(State.get(StartVPV, ScalarPHI), VectorPH);
3884-
return;
3885-
}
3886-
3887-
Value *Iden = getRecurrenceIdentity(RK, VecTy->getScalarType(),
3888-
RdxDesc.getFastMathFlags());
3889-
unsigned CurrentPart = getUnrollPart(*this);
3890-
Value *StartV = StartVPV->getLiveInIRValue();
3891-
if (!ScalarPHI) {
3892-
if (CurrentPart == 0) {
3893-
Iden = State.Builder.CreateVectorSplat(VF, Iden);
3894-
Constant *Zero = State.Builder.getInt32(0);
3895-
StartV = State.Builder.CreateInsertElement(Iden, StartV, Zero);
3896-
} else {
3897-
Iden = State.Builder.CreateVectorSplat(VF, Iden);
3898-
}
3899-
}
3900-
3901-
Value *StartVal = (CurrentPart == 0) ? StartV : Iden;
3902-
Phi->addIncoming(StartVal, VectorPH);
3882+
Phi->addIncoming(StartV, VectorPH);
39033883
}
39043884

39053885
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,16 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11551155
return;
11561156
}
11571157
}
1158+
// Simplify redundant ReductionStartVector recipes after unrolling.
1159+
VPValue *StartV;
1160+
if (match(Def, m_VPInstruction<VPInstruction::ReductionStartVector>(
1161+
m_VPValue(StartV), m_VPValue(), m_VPValue()))) {
1162+
Def->replaceUsesWithIf(StartV, [Def](const VPUser &U, unsigned Idx) {
1163+
auto *PhiR = dyn_cast<VPReductionPHIRecipe>(&U);
1164+
return PhiR && Def == PhiR->getOperand(Idx) && PhiR->isInLoop();
1165+
});
1166+
return;
1167+
}
11581168
}
11591169

11601170
void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) {

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,23 @@ void UnrollState::unrollHeaderPHIByUF(VPHeaderPHIRecipe *R,
223223
Copy->addOperand(R);
224224
Copy->addOperand(getConstantVPV(Part));
225225
} else if (RdxPhi) {
226+
// If the start value is a ReductionStartVector, use the identity value
227+
// (second operand) for unrolled parts. If the scaling factor is > 1,
228+
// create a new ReductionStartVector with the scale factor and both
229+
// operands set to the identity value.
230+
if (auto *VPI = dyn_cast<VPInstruction>(RdxPhi->getStartValue())) {
231+
if (cast<ConstantInt>(VPI->getOperand(2)->getLiveInIRValue())
232+
->getZExtValue() == 1)
233+
Copy->setOperand(0, VPI->getOperand(1));
234+
else {
235+
if (Part == 1) {
236+
auto *C = VPI->clone();
237+
C->setOperand(0, C->getOperand(1));
238+
C->insertAfter(VPI);
239+
addUniformForAllParts(C);
240+
}
241+
}
242+
}
226243
Copy->addOperand(getConstantVPV(Part));
227244
} else {
228245
assert(isa<VPActiveLaneMaskPHIRecipe>(R) &&

llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-epilogue.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ define void @dotp_small_epilogue_vf(i64 %idx.neg, i8 %a) #1 {
161161
; CHECK-NEXT: [[BROADCAST_SPLATINSERT6:%.*]] = insertelement <4 x i8> poison, i8 [[A]], i64 0
162162
; CHECK-NEXT: [[BROADCAST_SPLAT7:%.*]] = shufflevector <4 x i8> [[BROADCAST_SPLATINSERT6]], <4 x i8> poison, <4 x i32> zeroinitializer
163163
; CHECK-NEXT: [[IND_END:%.*]] = add i64 [[IDX_NEG]], [[N_VEC5]]
164-
; CHECK-NEXT: [[TMP8:%.*]] = sext <4 x i8> [[BROADCAST_SPLAT7]] to <4 x i32>
165164
; CHECK-NEXT: [[TMP10:%.*]] = insertelement <4 x i32> zeroinitializer, i32 [[BC_MERGE_RDX]], i32 0
165+
; CHECK-NEXT: [[TMP8:%.*]] = sext <4 x i8> [[BROADCAST_SPLAT7]] to <4 x i32>
166166
; CHECK-NEXT: br label [[VEC_EPILOG_VECTOR_BODY:%.*]]
167167
; CHECK: vec.epilog.vector.body:
168168
; CHECK-NEXT: [[INDEX9:%.*]] = phi i64 [ [[IV]], [[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT14:%.*]], [[VEC_EPILOG_VECTOR_BODY]] ]

llvm/test/Transforms/LoopVectorize/PowerPC/exit-branch-cost.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ define i1 @select_exit_cond(ptr %start, ptr %end, i64 %N) {
153153
; CHECK-NEXT: [[N_MOD_VF24:%.*]] = urem i64 [[TMP2]], 2
154154
; CHECK-NEXT: [[N_VEC25:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF24]]
155155
; CHECK-NEXT: [[TMP56:%.*]] = getelementptr i8, ptr [[START]], i64 [[N_VEC25]]
156+
; CHECK-NEXT: [[TMP57:%.*]] = insertelement <2 x i64> zeroinitializer, i64 [[BC_MERGE_RDX]], i32 0
156157
; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <2 x i64> poison, i64 [[VEC_EPILOG_RESUME_VAL]], i64 0
157158
; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <2 x i64> [[DOTSPLATINSERT]], <2 x i64> poison, <2 x i32> zeroinitializer
158159
; CHECK-NEXT: [[INDUCTION:%.*]] = add <2 x i64> [[DOTSPLAT]], <i64 0, i64 1>
159-
; CHECK-NEXT: [[TMP57:%.*]] = insertelement <2 x i64> zeroinitializer, i64 [[BC_MERGE_RDX]], i32 0
160160
; CHECK-NEXT: br label %[[VEC_EPILOG_VECTOR_BODY:.*]]
161161
; CHECK: [[VEC_EPILOG_VECTOR_BODY]]:
162162
; CHECK-NEXT: [[INDEX38:%.*]] = phi i64 [ [[VEC_EPILOG_RESUME_VAL]], %[[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT32:%.*]], %[[VEC_EPILOG_VECTOR_BODY]] ]

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-cond-reduction.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ define i32 @cond_add_pred(ptr %a, i64 %n, i32 %start) {
277277
; IF-EVL-OUTLOOP-NEXT: [[TRIP_COUNT_MINUS_1:%.*]] = sub i64 [[N]], 1
278278
; IF-EVL-OUTLOOP-NEXT: [[TMP7:%.*]] = call i64 @llvm.vscale.i64()
279279
; IF-EVL-OUTLOOP-NEXT: [[TMP8:%.*]] = mul i64 [[TMP7]], 4
280+
; IF-EVL-OUTLOOP-NEXT: [[TMP9:%.*]] = insertelement <vscale x 4 x i32> zeroinitializer, i32 [[START]], i32 0
280281
; IF-EVL-OUTLOOP-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TRIP_COUNT_MINUS_1]], i64 0
281282
; IF-EVL-OUTLOOP-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT1]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
282-
; IF-EVL-OUTLOOP-NEXT: [[TMP9:%.*]] = insertelement <vscale x 4 x i32> zeroinitializer, i32 [[START]], i32 0
283283
; IF-EVL-OUTLOOP-NEXT: br label [[VECTOR_BODY:%.*]]
284284
; IF-EVL-OUTLOOP: vector.body:
285285
; IF-EVL-OUTLOOP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
@@ -581,8 +581,8 @@ define i32 @step_cond_add(ptr %a, i64 %n, i32 %start) {
581581
; NO-VP-OUTLOOP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
582582
; NO-VP-OUTLOOP-NEXT: [[TMP9:%.*]] = call i64 @llvm.vscale.i64()
583583
; NO-VP-OUTLOOP-NEXT: [[TMP10:%.*]] = mul i64 [[TMP9]], 4
584-
; NO-VP-OUTLOOP-NEXT: [[TMP12:%.*]] = call <vscale x 4 x i32> @llvm.stepvector.nxv4i32()
585584
; NO-VP-OUTLOOP-NEXT: [[TMP11:%.*]] = insertelement <vscale x 4 x i32> zeroinitializer, i32 [[START]], i32 0
585+
; NO-VP-OUTLOOP-NEXT: [[TMP12:%.*]] = call <vscale x 4 x i32> @llvm.stepvector.nxv4i32()
586586
; NO-VP-OUTLOOP-NEXT: [[TMP14:%.*]] = mul <vscale x 4 x i32> [[TMP12]], splat (i32 1)
587587
; NO-VP-OUTLOOP-NEXT: [[INDUCTION:%.*]] = add <vscale x 4 x i32> zeroinitializer, [[TMP14]]
588588
; NO-VP-OUTLOOP-NEXT: [[TMP16:%.*]] = trunc i64 [[TMP10]] to i32
@@ -771,8 +771,8 @@ define i32 @step_cond_add_pred(ptr %a, i64 %n, i32 %start) {
771771
; NO-VP-OUTLOOP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
772772
; NO-VP-OUTLOOP-NEXT: [[TMP9:%.*]] = call i64 @llvm.vscale.i64()
773773
; NO-VP-OUTLOOP-NEXT: [[TMP10:%.*]] = mul i64 [[TMP9]], 4
774-
; NO-VP-OUTLOOP-NEXT: [[TMP12:%.*]] = call <vscale x 4 x i32> @llvm.stepvector.nxv4i32()
775774
; NO-VP-OUTLOOP-NEXT: [[TMP11:%.*]] = insertelement <vscale x 4 x i32> zeroinitializer, i32 [[START]], i32 0
775+
; NO-VP-OUTLOOP-NEXT: [[TMP12:%.*]] = call <vscale x 4 x i32> @llvm.stepvector.nxv4i32()
776776
; NO-VP-OUTLOOP-NEXT: [[TMP14:%.*]] = mul <vscale x 4 x i32> [[TMP12]], splat (i32 1)
777777
; NO-VP-OUTLOOP-NEXT: [[INDUCTION:%.*]] = add <vscale x 4 x i32> zeroinitializer, [[TMP14]]
778778
; NO-VP-OUTLOOP-NEXT: [[TMP16:%.*]] = trunc i64 [[TMP10]] to i32

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-reduction.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ define i32 @mul(ptr %a, i64 %n, i32 %start) {
137137
; IF-EVL-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], 8
138138
; IF-EVL-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
139139
; IF-EVL-NEXT: [[TRIP_COUNT_MINUS_1:%.*]] = sub i64 [[N]], 1
140+
; IF-EVL-NEXT: [[TMP9:%.*]] = insertelement <8 x i32> splat (i32 1), i32 [[START:%.*]], i32 0
140141
; IF-EVL-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <8 x i64> poison, i64 [[TRIP_COUNT_MINUS_1]], i64 0
141142
; IF-EVL-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <8 x i64> [[BROADCAST_SPLATINSERT1]], <8 x i64> poison, <8 x i32> zeroinitializer
142-
; IF-EVL-NEXT: [[TMP9:%.*]] = insertelement <8 x i32> splat (i32 1), i32 [[START:%.*]], i32 0
143143
; IF-EVL-NEXT: br label [[FOR_BODY:%.*]]
144144
; IF-EVL: vector.body:
145145
; IF-EVL-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
@@ -1220,9 +1220,9 @@ define float @fmul(ptr %a, i64 %n, float %start) {
12201220
; IF-EVL-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], 8
12211221
; IF-EVL-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
12221222
; IF-EVL-NEXT: [[TRIP_COUNT_MINUS_1:%.*]] = sub i64 [[N]], 1
1223+
; IF-EVL-NEXT: [[TMP9:%.*]] = insertelement <8 x float> splat (float 1.000000e+00), float [[START:%.*]], i32 0
12231224
; IF-EVL-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <8 x i64> poison, i64 [[TRIP_COUNT_MINUS_1]], i64 0
12241225
; IF-EVL-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <8 x i64> [[BROADCAST_SPLATINSERT1]], <8 x i64> poison, <8 x i32> zeroinitializer
1225-
; IF-EVL-NEXT: [[TMP9:%.*]] = insertelement <8 x float> splat (float 1.000000e+00), float [[START:%.*]], i32 0
12261226
; IF-EVL-NEXT: br label [[FOR_BODY:%.*]]
12271227
; IF-EVL: vector.body:
12281228
; IF-EVL-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]

0 commit comments

Comments
 (0)