Skip to content

Commit a309215

Browse files
committed
[VPlan] Don't create live-outs for induction increments.
Follow up to fc9cd32 to also skip creating live-outs for IV increments, as those are also generated independent of VPlan for now.
1 parent c1d1a75 commit a309215

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,10 +2822,8 @@ void InnerLoopVectorizer::fixupIVUsers(PHINode *OrigPhi,
28222822
// In this case, if IV1 has an external use, we need to avoid adding both
28232823
// "last value of IV1" and "penultimate value of IV2". So, verify that we
28242824
// don't already have an incoming value for the middle block.
2825-
if (PHI->getBasicBlockIndex(MiddleBlock) == -1) {
2825+
if (PHI->getBasicBlockIndex(MiddleBlock) == -1)
28262826
PHI->addIncoming(I.second, MiddleBlock);
2827-
Plan.removeLiveOut(PHI);
2828-
}
28292827
}
28302828
}
28312829

@@ -8427,8 +8425,9 @@ static void addCanonicalIVRecipes(VPlan &Plan, Type *IdxTy, bool HasNUW,
84278425

84288426
// Add exit values to \p Plan. VPLiveOuts are added for each LCSSA phi in the
84298427
// original exit block.
8430-
static void addUsersInExitBlock(Loop *OrigLoop, VPRecipeBuilder &Builder,
8431-
VPlan &Plan) {
8428+
static void addUsersInExitBlock(
8429+
Loop *OrigLoop, VPRecipeBuilder &Builder, VPlan &Plan,
8430+
const MapVector<PHINode *, InductionDescriptor> &Inductions) {
84328431
BasicBlock *ExitBB = OrigLoop->getUniqueExitBlock();
84338432
BasicBlock *ExitingBB = OrigLoop->getExitingBlock();
84348433
// Only handle single-exit loops with unique exit blocks for now.
@@ -8446,7 +8445,12 @@ static void addUsersInExitBlock(Loop *OrigLoop, VPRecipeBuilder &Builder,
84468445
// live-outs.
84478446
if ((isa<VPWidenIntOrFpInductionRecipe>(V) &&
84488447
!cast<VPWidenIntOrFpInductionRecipe>(V)->getTruncInst()) ||
8449-
isa<VPWidenPointerInductionRecipe>(V))
8448+
isa<VPWidenPointerInductionRecipe>(V) ||
8449+
(isa<Instruction>(IncomingValue) &&
8450+
any_of(IncomingValue->users(), [&Inductions](User *U) {
8451+
auto *P = dyn_cast<PHINode>(U);
8452+
return P && Inductions.contains(P);
8453+
})))
84508454
continue;
84518455
Plan.addLiveOut(&ExitPhi, V);
84528456
}
@@ -8661,7 +8665,8 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
86618665
// and there is nothing to fix from vector loop; phis should have incoming
86628666
// from scalar loop only.
86638667
} else
8664-
addUsersInExitBlock(OrigLoop, RecipeBuilder, *Plan);
8668+
addUsersInExitBlock(OrigLoop, RecipeBuilder, *Plan,
8669+
Legal->getInductionVars());
86658670

86668671
assert(isa<VPRegionBlock>(Plan->getVectorLoopRegion()) &&
86678672
!Plan->getVectorLoopRegion()->getEntryBasicBlock()->empty() &&

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,11 +3471,6 @@ class VPlan {
34713471

34723472
void addLiveOut(PHINode *PN, VPValue *V);
34733473

3474-
void removeLiveOut(PHINode *PN) {
3475-
delete LiveOuts[PN];
3476-
LiveOuts.erase(PN);
3477-
}
3478-
34793474
const MapVector<PHINode *, VPLiveOut *> &getLiveOuts() const {
34803475
return LiveOuts;
34813476
}

llvm/test/Transforms/LoopVectorize/X86/pr39160.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"
44
target triple = "x86_64-unknown-linux-gnu"
55

66
; Make sure that we can compile the test without crash.
7-
define void @barney() {
7+
define void @barney(ptr %dst) {
88

99
; CHECK-LABEL: @barney(
1010
; CHECK: middle.block:
@@ -43,6 +43,8 @@ bb48: ; preds = %bb46
4343
bb50: ; preds = %bb50, %bb19
4444
%tmp52 = phi i32 [ %tmp55, %bb50 ], [ %tmp22, %bb19 ]
4545
%tmp53 = phi i64 [ %tmp56, %bb50 ], [ 1, %bb19 ]
46+
%gep = getelementptr inbounds i8, ptr %dst, i64 %tmp53
47+
store i8 1, ptr %gep
4648
%tmp54 = add i32 %tmp52, 12
4749
%tmp55 = add i32 %tmp52, 13
4850
%tmp56 = add nuw nsw i64 %tmp53, 1

llvm/test/Transforms/LoopVectorize/version-stride-with-integer-casts.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ define void @test_versioned_with_sext_use(i32 %offset, ptr %dst) {
3434
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr i32, ptr [[DST]], i64 [[TMP3]]
3535
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i32, ptr [[TMP4]], i32 0
3636
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[TMP5]], align 8
37-
; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP3]], 1
3837
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
3938
; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], 200
4039
; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
@@ -110,7 +109,6 @@ define void @test_versioned_with_zext_use(i32 %offset, ptr %dst) {
110109
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr i32, ptr [[DST]], i64 [[TMP3]]
111110
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr i32, ptr [[TMP4]], i32 0
112111
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[TMP5]], align 8
113-
; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP3]], 1
114112
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
115113
; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], 200
116114
; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
@@ -267,7 +265,6 @@ define void @test_versioned_with_different_uses(i32 %offset, ptr noalias %dst.1,
267265
; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i32, ptr [[DST_2]], i64 [[TMP3]]
268266
; CHECK-NEXT: [[TMP13:%.*]] = getelementptr i32, ptr [[TMP12]], i32 0
269267
; CHECK-NEXT: store <4 x i32> zeroinitializer, ptr [[TMP13]], align 8
270-
; CHECK-NEXT: [[TMP14:%.*]] = add i64 [[TMP3]], 1
271268
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
272269
; CHECK-NEXT: [[TMP15:%.*]] = icmp eq i64 [[INDEX_NEXT]], 200
273270
; CHECK-NEXT: br i1 [[TMP15]], label [[MIDDLE_BLOCK]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]

0 commit comments

Comments
 (0)