Skip to content

Commit d40346c

Browse files
committed
[VPlan] Expand WidenInt inductions with nuw/nsw
1 parent a8a0ffb commit d40346c

File tree

115 files changed

+859
-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.

115 files changed

+859
-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
@@ -7575,11 +7575,15 @@ createWidenInductionRecipes(VPInstruction *PhiR,
75757575
assert(Plan.getLiveIn(IndDesc.getStartValue()) == Start &&
75767576
"Start VPValue must match IndDesc's start value");
75777577

7578+
// It is always safe to copy over the NoWrap and FastMath flags. In
7579+
// particular, when folding tail by masking, the masked-off lanes are never
7580+
// used, so it is safe.
7581+
VPIRFlags Flags = vputils::getFlagsFromIndDesc(IndDesc);
75787582
VPValue *Step =
75797583
vputils::getOrCreateVPValueForSCEVExpr(Plan, IndDesc.getStep());
75807584
PHINode *Phi = cast<PHINode>(PhiR->getUnderlyingInstr());
75817585
return new VPWidenIntOrFpInductionRecipe(Phi, Start, Step, &Plan.getVF(),
7582-
IndDesc, PhiR->getDebugLoc());
7586+
IndDesc, Flags, PhiR->getDebugLoc());
75837587
}
75847588

75857589
VPHeaderPHIRecipe *
@@ -7633,10 +7637,15 @@ VPRecipeBuilder::tryToOptimizeInductionTruncate(VPInstruction *VPI,
76337637
PHINode *Phi = WidenIV->getPHINode();
76347638
VPValue *Start = WidenIV->getStartValue();
76357639
const InductionDescriptor &IndDesc = WidenIV->getInductionDescriptor();
7640+
7641+
// It is always safe to copy over the NoWrap and FastMath flags. In
7642+
// particular, when folding tail by masking, the masked-off lanes are never
7643+
// used, so it is safe.
7644+
VPIRFlags Flags = vputils::getFlagsFromIndDesc(IndDesc);
76367645
VPValue *Step =
76377646
vputils::getOrCreateVPValueForSCEVExpr(Plan, IndDesc.getStep());
7638-
return new VPWidenIntOrFpInductionRecipe(Phi, Start, Step, &Plan.getVF(),
7639-
IndDesc, I, VPI->getDebugLoc());
7647+
return new VPWidenIntOrFpInductionRecipe(
7648+
Phi, Start, Step, &Plan.getVF(), IndDesc, I, Flags, VPI->getDebugLoc());
76407649
}
76417650

76427651
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
@@ -2119,7 +2119,8 @@ class VPWidenInductionRecipe : public VPHeaderPHIRecipe {
21192119
/// A recipe for handling phi nodes of integer and floating-point inductions,
21202120
/// producing their vector values. This is an abstract recipe and must be
21212121
/// converted to concrete recipes before executing.
2122-
class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
2122+
class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe,
2123+
public VPIRFlags {
21232124
TruncInst *Trunc;
21242125

21252126
// If this recipe is unrolled it will have 2 additional operands.
@@ -2128,19 +2129,20 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
21282129
public:
21292130
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step,
21302131
VPValue *VF, const InductionDescriptor &IndDesc,
2131-
DebugLoc DL)
2132+
const VPIRFlags &Flags, DebugLoc DL)
21322133
: VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
21332134
Step, IndDesc, DL),
2134-
Trunc(nullptr) {
2135+
VPIRFlags(Flags), Trunc(nullptr) {
21352136
addOperand(VF);
21362137
}
21372138

21382139
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step,
21392140
VPValue *VF, const InductionDescriptor &IndDesc,
2140-
TruncInst *Trunc, DebugLoc DL)
2141+
TruncInst *Trunc, const VPIRFlags &Flags,
2142+
DebugLoc DL)
21412143
: VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
21422144
Step, IndDesc, DL),
2143-
Trunc(Trunc) {
2145+
VPIRFlags(Flags), Trunc(Trunc) {
21442146
addOperand(VF);
21452147
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
21462148
(void)Metadata;
@@ -2154,7 +2156,7 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
21542156
VPWidenIntOrFpInductionRecipe *clone() override {
21552157
return new VPWidenIntOrFpInductionRecipe(
21562158
getPHINode(), getStartValue(), getStepValue(), getVFValue(),
2157-
getInductionDescriptor(), Trunc, getDebugLoc());
2159+
getInductionDescriptor(), Trunc, *this, getDebugLoc());
21582160
}
21592161

21602162
VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
8080
VPValue *Start = Plan.getOrAddLiveIn(II->getStartValue());
8181
VPValue *Step =
8282
vputils::getOrCreateVPValueForSCEVExpr(Plan, II->getStep());
83+
// It is always safe to copy over the NoWrap and FastMath flags. In
84+
// particular, when folding tail by masking, the masked-off lanes are
85+
// never used, so it is safe.
86+
VPIRFlags Flags = vputils::getFlagsFromIndDesc(*II);
8387
NewRecipe = new VPWidenIntOrFpInductionRecipe(
84-
Phi, Start, Step, &Plan.getVF(), *II, Ingredient.getDebugLoc());
88+
Phi, Start, Step, &Plan.getVF(), *II, Flags,
89+
Ingredient.getDebugLoc());
8590
}
8691
} else {
8792
assert(isa<VPInstruction>(&Ingredient) &&
@@ -546,6 +551,8 @@ static void removeRedundantCanonicalIVs(VPlan &Plan) {
546551
// only.
547552
if (!vputils::onlyScalarValuesUsed(WidenOriginalIV) ||
548553
vputils::onlyFirstLaneUsed(WidenNewIV)) {
554+
// Drop poison-generating flags when performing replacement.
555+
WidenOriginalIV->dropPoisonGeneratingFlags();
549556
WidenNewIV->replaceAllUsesWith(WidenOriginalIV);
550557
WidenNewIV->eraseFromParent();
551558
return;
@@ -3227,16 +3234,13 @@ expandVPWidenIntOrFpInduction(VPWidenIntOrFpInductionRecipe *WidenIVR,
32273234
const InductionDescriptor &ID = WidenIVR->getInductionDescriptor();
32283235
Instruction::BinaryOps AddOp;
32293236
Instruction::BinaryOps MulOp;
3230-
// FIXME: The newly created binary instructions should contain nsw/nuw
3231-
// flags, which can be found from the original scalar operations.
3232-
VPIRFlags Flags;
3237+
VPIRFlags Flags = *WidenIVR;
32333238
if (ID.getKind() == InductionDescriptor::IK_IntInduction) {
32343239
AddOp = Instruction::Add;
32353240
MulOp = Instruction::Mul;
32363241
} else {
32373242
AddOp = ID.getInductionOpcode();
32383243
MulOp = Instruction::FMul;
3239-
Flags = ID.getInductionBinOp()->getFastMathFlags();
32403244
}
32413245

32423246
// 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
@@ -71,6 +71,19 @@ std::optional<VPValue *>
7171
getRecipesForUncountableExit(VPlan &Plan,
7272
SmallVectorImpl<VPRecipeBase *> &Recipes,
7373
SmallVectorImpl<VPRecipeBase *> &GEPs);
74+
75+
/// Extracts and returns NoWrap and FastMath flags from the induction binop in
76+
/// \p ID.
77+
inline VPIRFlags getFlagsFromIndDesc(const InductionDescriptor &ID) {
78+
if (ID.getKind() == InductionDescriptor::IK_FpInduction)
79+
return ID.getInductionBinOp()->getFastMathFlags();
80+
81+
if (auto *OBO = dyn_cast_if_present<OverflowingBinaryOperator>(
82+
ID.getInductionBinOp()))
83+
return VPIRFlags::WrapFlagsTy(OBO->hasNoUnsignedWrap(),
84+
OBO->hasNoSignedWrap());
85+
return {};
86+
}
7487
} // namespace vputils
7588

7689
//===----------------------------------------------------------------------===//

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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,16 +660,16 @@ define void @low_trip_count_fold_tail_scalarized_store(ptr %dst) {
660660
; COMMON-NEXT: store i8 6, ptr [[TMP6]], align 1
661661
; COMMON-NEXT: br label %[[PRED_STORE_CONTINUE12]]
662662
; COMMON: [[PRED_STORE_CONTINUE12]]:
663-
; COMMON-NEXT: br i1 false, label %[[PRED_STORE_IF13:.*]], label %[[EXIT:.*]]
663+
; COMMON-NEXT: br i1 false, label %[[PRED_STORE_IF13:.*]], label %[[PRED_STORE_CONTINUE14:.*]]
664664
; COMMON: [[PRED_STORE_IF13]]:
665665
; COMMON-NEXT: [[TMP7:%.*]] = getelementptr i8, ptr [[DST]], i64 7
666666
; COMMON-NEXT: store i8 7, ptr [[TMP7]], align 1
667-
; COMMON-NEXT: br label %[[EXIT]]
667+
; COMMON-NEXT: br label %[[PRED_STORE_CONTINUE14]]
668+
; COMMON: [[PRED_STORE_CONTINUE14]]:
669+
; COMMON-NEXT: br label %[[MIDDLE_BLOCK:.*]]
670+
; COMMON: [[MIDDLE_BLOCK]]:
671+
; COMMON-NEXT: br label %[[EXIT:.*]]
668672
; COMMON: [[EXIT]]:
669-
; COMMON-NEXT: br label %[[SCALAR_PH:.*]]
670-
; COMMON: [[SCALAR_PH]]:
671-
; COMMON-NEXT: br label %[[EXIT1:.*]]
672-
; COMMON: [[EXIT1]]:
673673
; COMMON-NEXT: ret void
674674
;
675675
entry:
@@ -1110,7 +1110,7 @@ define void @redundant_branch_and_tail_folding(ptr %dst, i1 %c) {
11101110
; DEFAULT-NEXT: [[TMP2:%.*]] = extractelement <4 x i32> [[TMP1]], i32 3
11111111
; DEFAULT-NEXT: store i32 [[TMP2]], ptr [[DST]], align 4
11121112
; DEFAULT-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
1113-
; DEFAULT-NEXT: [[VEC_IND_NEXT]] = add <4 x i64> [[STEP_ADD]], splat (i64 4)
1113+
; DEFAULT-NEXT: [[VEC_IND_NEXT]] = add nuw nsw <4 x i64> [[STEP_ADD]], splat (i64 4)
11141114
; DEFAULT-NEXT: [[TMP3:%.*]] = icmp eq i64 [[INDEX_NEXT]], 16
11151115
; DEFAULT-NEXT: br i1 [[TMP3]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP27:![0-9]+]]
11161116
; 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)