Skip to content

Commit 53266f7

Browse files
committed
[VPlan] Run DCE after unrolling.
This cleans up a number of dead recipes after unrolling if only their first or last parts are used. This simplifies a number of tests. Fixes #109581.
1 parent 0e21c8e commit 53266f7

File tree

72 files changed

+2368
-3342
lines changed

Some content is hidden

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

72 files changed

+2368
-3342
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static bool isDeadRecipe(VPRecipeBase &R) {
510510
[](VPValue *V) { return V->getNumUsers() == 0; });
511511
}
512512

513-
static void removeDeadRecipes(VPlan &Plan) {
513+
void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
514514
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
515515
Plan.getEntry());
516516

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ struct VPlanTransforms {
116116
static void createInterleaveGroups(
117117
const SmallPtrSetImpl<const InterleaveGroup<Instruction> *> &InterleaveGroups,
118118
VPRecipeBuilder &RecipeBuilder, bool ScalarEpilogueAllowed);
119+
120+
/// Remove dead recipes from \p Plan.
121+
static void removeDeadRecipes(VPlan &Plan);
119122
};
120123

121124
} // namespace llvm

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,6 @@ void VPlanTransforms::unrollByUF(VPlan &Plan, unsigned UF, LLVMContext &Ctx) {
472472
VPValue *In = Unroller.getValueForPart(LO->getOperand(0), UF - 1);
473473
LO->setOperand(0, In);
474474
}
475+
476+
VPlanTransforms::removeDeadRecipes(Plan);
475477
}

llvm/test/Transforms/LoopVectorize/AArch64/call-costs.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ define void @fshl_operand_first_order_recurrence(ptr %dst, ptr noalias %src) {
1414
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
1515
; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <2 x i64> [ <i64 poison, i64 0>, %[[VECTOR_PH]] ], [ [[WIDE_LOAD1:%.*]], %[[VECTOR_BODY]] ]
1616
; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
17-
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 2
1817
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[SRC]], i64 [[TMP0]]
19-
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[SRC]], i64 [[TMP1]]
2018
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
2119
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 2
2220
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x i64>, ptr [[TMP4]], align 8
@@ -26,7 +24,6 @@ define void @fshl_operand_first_order_recurrence(ptr %dst, ptr noalias %src) {
2624
; CHECK-NEXT: [[TMP8:%.*]] = call <2 x i64> @llvm.fshl.v2i64(<2 x i64> <i64 1, i64 1>, <2 x i64> [[TMP6]], <2 x i64> <i64 1, i64 1>)
2725
; CHECK-NEXT: [[TMP9:%.*]] = call <2 x i64> @llvm.fshl.v2i64(<2 x i64> <i64 1, i64 1>, <2 x i64> [[TMP7]], <2 x i64> <i64 1, i64 1>)
2826
; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i64, ptr [[DST]], i64 [[TMP0]]
29-
; CHECK-NEXT: [[TMP11:%.*]] = getelementptr inbounds i64, ptr [[DST]], i64 [[TMP1]]
3027
; CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds i64, ptr [[TMP10]], i32 0
3128
; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i64, ptr [[TMP10]], i32 2
3229
; CHECK-NEXT: store <2 x i64> [[TMP8]], ptr [[TMP12]], align 8

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ define void @loop_dependent_cond(ptr %src, ptr noalias %dst, i64 %N) {
8282
; DEFAULT: vector.body:
8383
; DEFAULT-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_STORE_CONTINUE7:%.*]] ]
8484
; DEFAULT-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 0
85-
; DEFAULT-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 2
8685
; DEFAULT-NEXT: [[TMP3:%.*]] = getelementptr double, ptr [[SRC]], i64 [[TMP1]]
87-
; DEFAULT-NEXT: [[TMP4:%.*]] = getelementptr double, ptr [[SRC]], i64 [[TMP2]]
8886
; DEFAULT-NEXT: [[TMP5:%.*]] = getelementptr double, ptr [[TMP3]], i32 0
8987
; DEFAULT-NEXT: [[TMP6:%.*]] = getelementptr double, ptr [[TMP3]], i32 2
9088
; DEFAULT-NEXT: [[WIDE_LOAD:%.*]] = load <2 x double>, ptr [[TMP5]], align 8
@@ -344,9 +342,7 @@ define void @latch_branch_cost(ptr %dst) {
344342
; DEFAULT: vector.body:
345343
; DEFAULT-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH1]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
346344
; DEFAULT-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
347-
; DEFAULT-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 16
348345
; DEFAULT-NEXT: [[TMP2:%.*]] = getelementptr i8, ptr [[DST]], i64 [[TMP0]]
349-
; DEFAULT-NEXT: [[TMP3:%.*]] = getelementptr i8, ptr [[DST]], i64 [[TMP1]]
350346
; DEFAULT-NEXT: [[TMP6:%.*]] = getelementptr i8, ptr [[TMP2]], i32 0
351347
; DEFAULT-NEXT: [[TMP5:%.*]] = getelementptr i8, ptr [[TMP2]], i32 16
352348
; DEFAULT-NEXT: store <16 x i8> zeroinitializer, ptr [[TMP6]], align 1

llvm/test/Transforms/LoopVectorize/AArch64/divs-with-scalable-vfs.ll

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,11 @@ define void @sdiv_feeding_gep(ptr %dst, i32 %x, i64 %M, i64 %conv6, i64 %N) {
3434
; CHECK: [[VECTOR_BODY]]:
3535
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
3636
; CHECK-NEXT: [[TMP12:%.*]] = add i64 [[INDEX]], 0
37-
; CHECK-NEXT: [[TMP13:%.*]] = call i64 @llvm.vscale.i64()
38-
; CHECK-NEXT: [[TMP14:%.*]] = mul i64 [[TMP13]], 2
39-
; CHECK-NEXT: [[TMP15:%.*]] = add i64 [[TMP14]], 0
40-
; CHECK-NEXT: [[TMP16:%.*]] = mul i64 [[TMP15]], 1
41-
; CHECK-NEXT: [[TMP17:%.*]] = add i64 [[INDEX]], [[TMP16]]
4237
; CHECK-NEXT: [[TMP24:%.*]] = sub i64 [[TMP12]], [[TMP22]]
43-
; CHECK-NEXT: [[TMP25:%.*]] = sub i64 [[TMP17]], [[TMP22]]
4438
; CHECK-NEXT: [[TMP26:%.*]] = trunc i64 [[TMP24]] to i32
45-
; CHECK-NEXT: [[TMP27:%.*]] = trunc i64 [[TMP25]] to i32
4639
; CHECK-NEXT: [[TMP30:%.*]] = add i32 [[TMP28]], [[TMP26]]
47-
; CHECK-NEXT: [[TMP31:%.*]] = add i32 [[TMP28]], [[TMP27]]
4840
; CHECK-NEXT: [[TMP32:%.*]] = sext i32 [[TMP30]] to i64
49-
; CHECK-NEXT: [[TMP33:%.*]] = sext i32 [[TMP31]] to i64
5041
; CHECK-NEXT: [[TMP34:%.*]] = getelementptr double, ptr [[DST]], i64 [[TMP32]]
51-
; CHECK-NEXT: [[TMP35:%.*]] = getelementptr double, ptr [[DST]], i64 [[TMP33]]
5242
; CHECK-NEXT: [[TMP36:%.*]] = getelementptr double, ptr [[TMP34]], i32 0
5343
; CHECK-NEXT: [[TMP37:%.*]] = call i64 @llvm.vscale.i64()
5444
; CHECK-NEXT: [[TMP38:%.*]] = mul i64 [[TMP37]], 2

0 commit comments

Comments
 (0)