Skip to content

Commit 355e0f9

Browse files
authored
[VPlan] Expand WidenInt inductions with nuw/nsw (#163538)
While at it, record VPIRFlags in VPWidenInductionRecipe.
1 parent 056f744 commit 355e0f9

File tree

119 files changed

+864
-793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+864
-793
lines changed

flang/test/Integration/unroll-loops.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ subroutine unroll(a)
2525
! NO-UNROLL-NEXT: %[[GEP:.*]] = getelementptr i64, ptr %[[ARG0]], i64 %[[IND]]
2626
! NO-UNROLL-NEXT: store <2 x i64> %[[VIND]], ptr %[[GEP]]
2727
! NO-UNROLL-NEXT: %[[NIV:.*]] = add nuw i64 %{{.*}}, 2
28-
! NO-UNROLL-NEXT: %[[NVIND]] = add <2 x i64> %[[VIND]], splat (i64 2)
28+
! NO-UNROLL-NEXT: %[[NVIND]] = add nuw nsw <2 x i64> %[[VIND]], splat (i64 2)
2929
!
3030
! UNROLL-NEXT: %[[VIND1:.*]] = add <2 x i64> %[[VIND]], splat (i64 2)
3131
! UNROLL-NEXT: %[[GEP0:.*]] = getelementptr i64, ptr %[[ARG0]], i64 %[[IND]]

flang/test/Lower/HLFIR/unroll-loops.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func.func @unroll(%arg0: !fir.ref<!fir.array<1000 x index>> {fir.bindc_name = "a
2727
// NO-UNROLL-NEXT: %[[GEP:.*]] = getelementptr i64, ptr %[[ARG0]], i64 %[[IND]]
2828
// NO-UNROLL-NEXT: store <2 x i64> %[[VIND]], ptr %[[GEP]]
2929
// NO-UNROLL-NEXT: %[[NIV:.*]] = add nuw i64 %{{.*}}, 2
30-
// NO-UNROLL-NEXT: %[[NVIND]] = add <2 x i64> %[[VIND]], splat (i64 2)
30+
// NO-UNROLL-NEXT: %[[NVIND]] = add nuw nsw <2 x i64> %[[VIND]], splat (i64 2)
3131

3232
// UNROLL-NEXT: %[[VIND1:.*]] = add <2 x i64> %[[VIND]], splat (i64 2)
3333
// UNROLL-NEXT: %[[GEP0:.*]] = getelementptr i64, ptr %[[ARG0]], i64 %[[IND]]

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7639,6 +7639,10 @@ createWidenInductionRecipes(VPInstruction *PhiR,
76397639
assert(Plan.getLiveIn(IndDesc.getStartValue()) == Start &&
76407640
"Start VPValue must match IndDesc's start value");
76417641

7642+
// It is always safe to copy over the NoWrap and FastMath flags. In
7643+
// particular, when folding tail by masking, the masked-off lanes are never
7644+
// used, so it is safe.
7645+
VPIRFlags Flags = vputils::getFlagsFromIndDesc(IndDesc);
76427646
VPValue *Step =
76437647
vputils::getOrCreateVPValueForSCEVExpr(Plan, IndDesc.getStep());
76447648

@@ -7651,7 +7655,7 @@ createWidenInductionRecipes(VPInstruction *PhiR,
76517655

76527656
PHINode *Phi = cast<PHINode>(PhiR->getUnderlyingInstr());
76537657
return new VPWidenIntOrFpInductionRecipe(Phi, Start, Step, &Plan.getVF(),
7654-
IndDesc, PhiR->getDebugLoc());
7658+
IndDesc, Flags, PhiR->getDebugLoc());
76557659
}
76567660

76577661
VPHeaderPHIRecipe *
@@ -7705,10 +7709,15 @@ VPRecipeBuilder::tryToOptimizeInductionTruncate(VPInstruction *VPI,
77057709
PHINode *Phi = WidenIV->getPHINode();
77067710
VPValue *Start = WidenIV->getStartValue();
77077711
const InductionDescriptor &IndDesc = WidenIV->getInductionDescriptor();
7712+
7713+
// It is always safe to copy over the NoWrap and FastMath flags. In
7714+
// particular, when folding tail by masking, the masked-off lanes are never
7715+
// used, so it is safe.
7716+
VPIRFlags Flags = vputils::getFlagsFromIndDesc(IndDesc);
77087717
VPValue *Step =
77097718
vputils::getOrCreateVPValueForSCEVExpr(Plan, IndDesc.getStep());
7710-
return new VPWidenIntOrFpInductionRecipe(Phi, Start, Step, &Plan.getVF(),
7711-
IndDesc, I, VPI->getDebugLoc());
7719+
return new VPWidenIntOrFpInductionRecipe(
7720+
Phi, Start, Step, &Plan.getVF(), IndDesc, I, Flags, VPI->getDebugLoc());
77127721
}
77137722

77147723
VPSingleDefRecipe *VPRecipeBuilder::tryToWidenCall(VPInstruction *VPI,

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,8 @@ class VPWidenInductionRecipe : public VPHeaderPHIRecipe {
21242124
/// A recipe for handling phi nodes of integer and floating-point inductions,
21252125
/// producing their vector values. This is an abstract recipe and must be
21262126
/// converted to concrete recipes before executing.
2127-
class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
2127+
class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe,
2128+
public VPIRFlags {
21282129
TruncInst *Trunc;
21292130

21302131
// If this recipe is unrolled it will have 2 additional operands.
@@ -2133,19 +2134,20 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
21332134
public:
21342135
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step,
21352136
VPValue *VF, const InductionDescriptor &IndDesc,
2136-
DebugLoc DL)
2137+
const VPIRFlags &Flags, DebugLoc DL)
21372138
: VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
21382139
Step, IndDesc, DL),
2139-
Trunc(nullptr) {
2140+
VPIRFlags(Flags), Trunc(nullptr) {
21402141
addOperand(VF);
21412142
}
21422143

21432144
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step,
21442145
VPValue *VF, const InductionDescriptor &IndDesc,
2145-
TruncInst *Trunc, DebugLoc DL)
2146+
TruncInst *Trunc, const VPIRFlags &Flags,
2147+
DebugLoc DL)
21462148
: VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
21472149
Step, IndDesc, DL),
2148-
Trunc(Trunc) {
2150+
VPIRFlags(Flags), Trunc(Trunc) {
21492151
addOperand(VF);
21502152
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
21512153
(void)Metadata;
@@ -2159,7 +2161,7 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
21592161
VPWidenIntOrFpInductionRecipe *clone() override {
21602162
return new VPWidenIntOrFpInductionRecipe(
21612163
getPHINode(), getStartValue(), getStepValue(), getVFValue(),
2162-
getInductionDescriptor(), Trunc, getDebugLoc());
2164+
getInductionDescriptor(), Trunc, *this, getDebugLoc());
21632165
}
21642166

21652167
VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,9 @@ void VPWidenIntOrFpInductionRecipe::print(raw_ostream &O, const Twine &Indent,
23762376
VPSlotTracker &SlotTracker) const {
23772377
O << Indent;
23782378
printAsOperand(O, SlotTracker);
2379-
O << " = WIDEN-INDUCTION ";
2379+
O << " = WIDEN-INDUCTION";
2380+
printFlags(O);
2381+
O << " ";
23802382
printOperands(O, SlotTracker);
23812383

23822384
if (auto *TI = getTruncInst())

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
7676
VPValue *Start = Plan.getOrAddLiveIn(II->getStartValue());
7777
VPValue *Step =
7878
vputils::getOrCreateVPValueForSCEVExpr(Plan, II->getStep());
79+
// It is always safe to copy over the NoWrap and FastMath flags. In
80+
// particular, when folding tail by masking, the masked-off lanes are
81+
// never used, so it is safe.
82+
VPIRFlags Flags = vputils::getFlagsFromIndDesc(*II);
7983
NewRecipe = new VPWidenIntOrFpInductionRecipe(
80-
Phi, Start, Step, &Plan.getVF(), *II, Ingredient.getDebugLoc());
84+
Phi, Start, Step, &Plan.getVF(), *II, Flags,
85+
Ingredient.getDebugLoc());
8186
}
8287
} else {
8388
assert(isa<VPInstruction>(&Ingredient) &&
@@ -542,6 +547,11 @@ static void removeRedundantCanonicalIVs(VPlan &Plan) {
542547
// only.
543548
if (!vputils::onlyScalarValuesUsed(WidenOriginalIV) ||
544549
vputils::onlyFirstLaneUsed(WidenNewIV)) {
550+
// We are replacing a wide canonical iv with a suitable wide induction.
551+
// This is used to compute header mask, hence all lanes will be used and
552+
// we need to drop wrap flags only applying to lanes guranteed to execute
553+
// in the original scalar loop.
554+
WidenOriginalIV->dropPoisonGeneratingFlags();
545555
WidenNewIV->replaceAllUsesWith(WidenOriginalIV);
546556
WidenNewIV->eraseFromParent();
547557
return;
@@ -3290,16 +3300,13 @@ expandVPWidenIntOrFpInduction(VPWidenIntOrFpInductionRecipe *WidenIVR,
32903300
const InductionDescriptor &ID = WidenIVR->getInductionDescriptor();
32913301
Instruction::BinaryOps AddOp;
32923302
Instruction::BinaryOps MulOp;
3293-
// FIXME: The newly created binary instructions should contain nsw/nuw
3294-
// flags, which can be found from the original scalar operations.
3295-
VPIRFlags Flags;
3303+
VPIRFlags Flags = *WidenIVR;
32963304
if (ID.getKind() == InductionDescriptor::IK_IntInduction) {
32973305
AddOp = Instruction::Add;
32983306
MulOp = Instruction::Mul;
32993307
} else {
33003308
AddOp = ID.getInductionOpcode();
33013309
MulOp = Instruction::FMul;
3302-
Flags = ID.getInductionBinOp()->getFastMathFlags();
33033310
}
33043311

33053312
// If the phi is truncated, truncate the start and step values.

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ std::optional<VPValue *>
7373
getRecipesForUncountableExit(VPlan &Plan,
7474
SmallVectorImpl<VPRecipeBase *> &Recipes,
7575
SmallVectorImpl<VPRecipeBase *> &GEPs);
76+
77+
/// Extracts and returns NoWrap and FastMath flags from the induction binop in
78+
/// \p ID.
79+
inline VPIRFlags getFlagsFromIndDesc(const InductionDescriptor &ID) {
80+
if (ID.getKind() == InductionDescriptor::IK_FpInduction)
81+
return ID.getInductionBinOp()->getFastMathFlags();
82+
83+
if (auto *OBO = dyn_cast_if_present<OverflowingBinaryOperator>(
84+
ID.getInductionBinOp()))
85+
return VPIRFlags::WrapFlagsTy(OBO->hasNoUnsignedWrap(),
86+
OBO->hasNoSignedWrap());
87+
return {};
88+
}
7689
} // namespace vputils
7790

7891
//===----------------------------------------------------------------------===//

llvm/test/Transforms/LoopVectorize/AArch64/clamped-trip-count.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ define void @clamped_tc_8(ptr nocapture %dst, i32 %n, i64 %val) vscale_range(1,1
1414
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 8 x i64> poison, i64 [[VAL]], i64 0
1515
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 8 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer
1616
; CHECK-NEXT: [[TMP8:%.*]] = call <vscale x 8 x i64> @llvm.stepvector.nxv8i64()
17-
; CHECK-NEXT: [[TMP7:%.*]] = mul <vscale x 8 x i64> [[TMP8]], splat (i64 1)
18-
; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 8 x i64> zeroinitializer, [[TMP7]]
17+
; CHECK-NEXT: [[TMP3:%.*]] = mul <vscale x 8 x i64> [[TMP8]], splat (i64 1)
18+
; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 8 x i64> zeroinitializer, [[TMP3]]
1919
; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 8 x i64> poison, i64 [[TMP1]], i64 0
2020
; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 8 x i64> [[DOTSPLATINSERT]], <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer
2121
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
@@ -76,8 +76,8 @@ define void @clamped_tc_max_8(ptr nocapture %dst, i32 %n, i64 %val) vscale_range
7676
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 8 x i64> poison, i64 [[VAL]], i64 0
7777
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 8 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer
7878
; CHECK-NEXT: [[TMP8:%.*]] = call <vscale x 8 x i64> @llvm.stepvector.nxv8i64()
79-
; CHECK-NEXT: [[TMP7:%.*]] = mul <vscale x 8 x i64> [[TMP8]], splat (i64 1)
80-
; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 8 x i64> zeroinitializer, [[TMP7]]
79+
; CHECK-NEXT: [[TMP3:%.*]] = mul <vscale x 8 x i64> [[TMP8]], splat (i64 1)
80+
; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 8 x i64> zeroinitializer, [[TMP3]]
8181
; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 8 x i64> poison, i64 [[TMP1]], i64 0
8282
; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 8 x i64> [[DOTSPLATINSERT]], <vscale x 8 x i64> poison, <vscale x 8 x i32> zeroinitializer
8383
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]

llvm/test/Transforms/LoopVectorize/AArch64/conditional-branches-cost.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ define void @redundant_branch_and_tail_folding(ptr %dst, i1 %c) {
10521052
; DEFAULT-NEXT: [[TMP2:%.*]] = extractelement <4 x i32> [[TMP1]], i32 3
10531053
; DEFAULT-NEXT: store i32 [[TMP2]], ptr [[DST]], align 4
10541054
; DEFAULT-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
1055-
; DEFAULT-NEXT: [[VEC_IND_NEXT]] = add <4 x i64> [[STEP_ADD]], splat (i64 4)
1055+
; DEFAULT-NEXT: [[VEC_IND_NEXT]] = add nuw nsw <4 x i64> [[STEP_ADD]], splat (i64 4)
10561056
; DEFAULT-NEXT: [[TMP3:%.*]] = icmp eq i64 [[INDEX_NEXT]], 16
10571057
; DEFAULT-NEXT: br i1 [[TMP3]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP27:![0-9]+]]
10581058
; DEFAULT: [[MIDDLE_BLOCK]]:

llvm/test/Transforms/LoopVectorize/AArch64/epilog-iv-select-cmp.ll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ define i8 @select_icmp_var_start(ptr %a, i8 %n, i8 %start) {
3535
; CHECK-NEXT: [[TMP10]] = select <16 x i1> [[TMP17]], <16 x i8> [[VEC_IND]], <16 x i8> [[VEC_PHI]]
3636
; CHECK-NEXT: [[TMP11]] = select <16 x i1> [[TMP23]], <16 x i8> [[STEP_ADD]], <16 x i8> [[VEC_PHI2]]
3737
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 32
38-
; CHECK-NEXT: [[VEC_IND_NEXT]] = add <16 x i8> [[STEP_ADD]], splat (i8 16)
38+
; CHECK-NEXT: [[VEC_IND_NEXT]] = add nuw nsw <16 x i8> [[STEP_ADD]], splat (i8 16)
3939
; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4040
; CHECK-NEXT: br i1 [[TMP12]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
4141
; CHECK: [[MIDDLE_BLOCK]]:
@@ -48,7 +48,7 @@ define i8 @select_icmp_var_start(ptr %a, i8 %n, i8 %start) {
4848
; CHECK: [[VEC_EPILOG_ITER_CHECK]]:
4949
; CHECK-NEXT: [[IND_END:%.*]] = trunc i32 [[N_VEC]] to i8
5050
; CHECK-NEXT: [[MIN_EPILOG_ITERS_CHECK:%.*]] = icmp ult i32 [[N_MOD_VF]], 8
51-
; CHECK-NEXT: br i1 [[MIN_EPILOG_ITERS_CHECK]], label %[[VEC_EPILOG_SCALAR_PH]], label %[[VEC_EPILOG_PH]]
51+
; CHECK-NEXT: br i1 [[MIN_EPILOG_ITERS_CHECK]], label %[[VEC_EPILOG_SCALAR_PH]], label %[[VEC_EPILOG_PH]], !prof [[PROF3:![0-9]+]]
5252
; CHECK: [[VEC_EPILOG_PH]]:
5353
; CHECK-NEXT: [[VEC_EPILOG_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], %[[VEC_EPILOG_ITER_CHECK]] ], [ 0, %[[VECTOR_MAIN_LOOP_ITER_CHECK]] ]
5454
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i8 [ [[TMP3]], %[[VEC_EPILOG_ITER_CHECK]] ], [ 0, %[[VECTOR_MAIN_LOOP_ITER_CHECK]] ]
@@ -62,21 +62,21 @@ define i8 @select_icmp_var_start(ptr %a, i8 %n, i8 %start) {
6262
; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <8 x i8> [[DOTSPLATINSERT]], <8 x i8> poison, <8 x i32> zeroinitializer
6363
; CHECK-NEXT: [[DOTSPLATINSERT10:%.*]] = insertelement <8 x i8> poison, i8 [[BC_RESUME_VAL]], i64 0
6464
; CHECK-NEXT: [[DOTSPLAT11:%.*]] = shufflevector <8 x i8> [[DOTSPLATINSERT10]], <8 x i8> poison, <8 x i32> zeroinitializer
65-
; CHECK-NEXT: [[INDUCTION:%.*]] = add <8 x i8> [[DOTSPLAT11]], <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7>
65+
; CHECK-NEXT: [[INDUCTION:%.*]] = add nuw nsw <8 x i8> [[DOTSPLAT11]], <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7>
6666
; CHECK-NEXT: br label %[[VEC_EPILOG_VECTOR_BODY:.*]]
6767
; CHECK: [[VEC_EPILOG_VECTOR_BODY]]:
6868
; CHECK-NEXT: [[INDEX6:%.*]] = phi i32 [ [[VEC_EPILOG_RESUME_VAL]], %[[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT13:%.*]], %[[VEC_EPILOG_VECTOR_BODY]] ]
69-
; CHECK-NEXT: [[VEC_IND7:%.*]] = phi <8 x i8> [ [[INDUCTION]], %[[VEC_EPILOG_PH]] ], [ [[VEC_IND_NEXT8:%.*]], %[[VEC_EPILOG_VECTOR_BODY]] ]
69+
; CHECK-NEXT: [[VEC_IND7:%.*]] = phi <8 x i8> [ [[INDUCTION]], %[[VEC_EPILOG_PH]] ], [ [[VEC_IND_NEXT13:%.*]], %[[VEC_EPILOG_VECTOR_BODY]] ]
7070
; CHECK-NEXT: [[VEC_PHI9:%.*]] = phi <8 x i8> [ [[DOTSPLAT]], %[[VEC_EPILOG_PH]] ], [ [[TMP20:%.*]], %[[VEC_EPILOG_VECTOR_BODY]] ]
7171
; CHECK-NEXT: [[IV:%.*]] = trunc i32 [[INDEX6]] to i8
7272
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[A]], i8 [[IV]]
7373
; CHECK-NEXT: [[WIDE_LOAD12:%.*]] = load <8 x i8>, ptr [[GEP]], align 8
7474
; CHECK-NEXT: [[TMP19:%.*]] = icmp eq <8 x i8> [[WIDE_LOAD12]], splat (i8 3)
7575
; CHECK-NEXT: [[TMP20]] = select <8 x i1> [[TMP19]], <8 x i8> [[VEC_IND7]], <8 x i8> [[VEC_PHI9]]
7676
; CHECK-NEXT: [[INDEX_NEXT13]] = add nuw i32 [[INDEX6]], 8
77-
; CHECK-NEXT: [[VEC_IND_NEXT8]] = add <8 x i8> [[VEC_IND7]], splat (i8 8)
77+
; CHECK-NEXT: [[VEC_IND_NEXT13]] = add nuw nsw <8 x i8> [[VEC_IND7]], splat (i8 8)
7878
; CHECK-NEXT: [[TMP21:%.*]] = icmp eq i32 [[INDEX_NEXT13]], [[N_VEC5]]
79-
; CHECK-NEXT: br i1 [[TMP21]], label %[[VEC_EPILOG_MIDDLE_BLOCK:.*]], label %[[VEC_EPILOG_VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
79+
; CHECK-NEXT: br i1 [[TMP21]], label %[[VEC_EPILOG_MIDDLE_BLOCK:.*]], label %[[VEC_EPILOG_VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
8080
; CHECK: [[VEC_EPILOG_MIDDLE_BLOCK]]:
8181
; CHECK-NEXT: [[TMP22:%.*]] = call i8 @llvm.vector.reduce.smax.v8i8(<8 x i8> [[TMP20]])
8282
; CHECK-NEXT: [[RDX_SELECT_CMP14:%.*]] = icmp ne i8 [[TMP22]], -128
@@ -96,7 +96,7 @@ define i8 @select_icmp_var_start(ptr %a, i8 %n, i8 %start) {
9696
; CHECK-NEXT: [[SEL]] = select i1 [[C]], i8 [[IV1]], i8 [[RDX]]
9797
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV1]], 1
9898
; CHECK-NEXT: [[EC:%.*]] = icmp eq i8 [[IV_NEXT]], [[N]]
99-
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP4:![0-9]+]]
99+
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]
100100
; CHECK: [[EXIT]]:
101101
; CHECK-NEXT: [[SEL_LCSSA:%.*]] = phi i8 [ [[SEL]], %[[LOOP]] ], [ [[RDX_SELECT]], %[[MIDDLE_BLOCK]] ], [ [[RDX_SELECT15]], %[[VEC_EPILOG_MIDDLE_BLOCK]] ]
102102
; CHECK-NEXT: ret i8 [[SEL_LCSSA]]
@@ -158,7 +158,7 @@ define i32 @select_icmp_var_start_iv_trunc(i32 %N, i32 %start) #0 {
158158
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
159159
; CHECK-NEXT: [[VEC_IND_NEXT]] = add <4 x i32> [[STEP_ADD_3]], splat (i32 4)
160160
; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
161-
; CHECK-NEXT: br i1 [[TMP7]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
161+
; CHECK-NEXT: br i1 [[TMP7]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
162162
; CHECK: [[MIDDLE_BLOCK]]:
163163
; CHECK-NEXT: [[RDX_MINMAX:%.*]] = call <4 x i32> @llvm.smax.v4i32(<4 x i32> [[TMP3]], <4 x i32> [[TMP4]])
164164
; CHECK-NEXT: [[RDX_MINMAX5:%.*]] = call <4 x i32> @llvm.smax.v4i32(<4 x i32> [[RDX_MINMAX]], <4 x i32> [[TMP5]])
@@ -170,7 +170,7 @@ define i32 @select_icmp_var_start_iv_trunc(i32 %N, i32 %start) #0 {
170170
; CHECK-NEXT: br i1 [[CMP_N]], label %[[EXIT:.*]], label %[[VEC_EPILOG_ITER_CHECK:.*]]
171171
; CHECK: [[VEC_EPILOG_ITER_CHECK]]:
172172
; CHECK-NEXT: [[MIN_EPILOG_ITERS_CHECK:%.*]] = icmp ult i64 [[N_MOD_VF]], 4
173-
; CHECK-NEXT: br i1 [[MIN_EPILOG_ITERS_CHECK]], label %[[VEC_EPILOG_SCALAR_PH]], label %[[VEC_EPILOG_PH]]
173+
; CHECK-NEXT: br i1 [[MIN_EPILOG_ITERS_CHECK]], label %[[VEC_EPILOG_SCALAR_PH]], label %[[VEC_EPILOG_PH]], !prof [[PROF7:![0-9]+]]
174174
; CHECK: [[VEC_EPILOG_PH]]:
175175
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[VEC_EPILOG_ITER_CHECK]] ], [ 0, %[[VECTOR_MAIN_LOOP_ITER_CHECK]] ]
176176
; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[RDX_SELECT]], %[[VEC_EPILOG_ITER_CHECK]] ], [ [[FR]], %[[VECTOR_MAIN_LOOP_ITER_CHECK]] ]
@@ -197,7 +197,7 @@ define i32 @select_icmp_var_start_iv_trunc(i32 %N, i32 %start) #0 {
197197
; CHECK-NEXT: [[INDEX_NEXT17]] = add nuw i64 [[INDEX11]], 4
198198
; CHECK-NEXT: [[VEC_IND_NEXT16]] = add <4 x i32> [[VEC_IND15]], splat (i32 4)
199199
; CHECK-NEXT: [[TMP15:%.*]] = icmp eq i64 [[INDEX_NEXT17]], [[N_VEC8]]
200-
; CHECK-NEXT: br i1 [[TMP15]], label %[[VEC_EPILOG_MIDDLE_BLOCK:.*]], label %[[VEC_EPILOG_VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
200+
; CHECK-NEXT: br i1 [[TMP15]], label %[[VEC_EPILOG_MIDDLE_BLOCK:.*]], label %[[VEC_EPILOG_VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
201201
; CHECK: [[VEC_EPILOG_MIDDLE_BLOCK]]:
202202
; CHECK-NEXT: [[TMP16:%.*]] = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> [[TMP14]])
203203
; CHECK-NEXT: [[RDX_SELECT_CMP18:%.*]] = icmp ne i32 [[TMP16]], -2147483648
@@ -216,7 +216,7 @@ define i32 @select_icmp_var_start_iv_trunc(i32 %N, i32 %start) #0 {
216216
; CHECK-NEXT: [[RED_NEXT]] = select i1 [[C]], i32 [[IV_TRUNC]], i32 [[RED]]
217217
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
218218
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV]], [[N_EXT]]
219-
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP7:![0-9]+]]
219+
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP9:![0-9]+]]
220220
; CHECK: [[EXIT]]:
221221
; CHECK-NEXT: [[RED_NEXT_LCSSA:%.*]] = phi i32 [ [[RED_NEXT]], %[[LOOP]] ], [ [[RDX_SELECT]], %[[MIDDLE_BLOCK]] ], [ [[RDX_SELECT19]], %[[VEC_EPILOG_MIDDLE_BLOCK]] ]
222222
; CHECK-NEXT: ret i32 [[RED_NEXT_LCSSA]]

0 commit comments

Comments
 (0)