Skip to content

Commit 7346e7c

Browse files
committed
[VPlan] Update HCFG builder after 7293720 to fix leak.
Update buildPlainCFG to re-use the vector and latch VPBBs created as part of the initial skeleton in 7293720. This should fix the leak sanitizer failure discovered by https://lab.llvm.org/buildbot/#/builders/52/builds/619.
1 parent 997e5e8 commit 7346e7c

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,24 @@ void PlainCFGBuilder::buildPlainCFG() {
346346
// latter.
347347
BB2VPBB[ThePreheaderBB] = VectorPreheaderVPBB;
348348
BasicBlock *LoopExitBB = TheLoop->getUniqueExitBlock();
349+
Loop2Region[LI->getLoopFor(TheLoop->getHeader())] = TheRegion;
349350
assert(LoopExitBB && "Loops with multiple exits are not supported.");
350351
BB2VPBB[LoopExitBB] = cast<VPBasicBlock>(TheRegion->getSingleSuccessor());
351352

353+
// The existing vector region's entry and exiting VPBBs correspond to the loop
354+
// header and latch.
355+
VPBasicBlock *VectorHeaderVPBB = TheRegion->getEntryBasicBlock();
356+
VPBasicBlock *VectorLatchVPBB = TheRegion->getExitingBasicBlock();
357+
BB2VPBB[TheLoop->getHeader()] = VectorHeaderVPBB;
358+
VectorHeaderVPBB->clearSuccessors();
359+
VectorLatchVPBB->clearPredecessors();
360+
if (TheLoop->getHeader() != TheLoop->getLoopLatch()) {
361+
BB2VPBB[TheLoop->getLoopLatch()] = VectorLatchVPBB;
362+
} else {
363+
TheRegion->setExiting(VectorHeaderVPBB);
364+
delete VectorLatchVPBB;
365+
}
366+
352367
// 1. Scan the body of the loop in a topological order to visit each basic
353368
// block after having visited its predecessor basic blocks. Create a VPBB for
354369
// each BB and link it to its successor and predecessor VPBBs. Note that
@@ -413,10 +428,11 @@ void PlainCFGBuilder::buildPlainCFG() {
413428
// of VPBB and it should be set to the exit, i.e., non-header successor,
414429
// except for the top region, whose successor was set when creating VPlan's
415430
// skeleton.
416-
if (TheRegion != Region)
431+
if (TheRegion != Region) {
417432
Region->setOneSuccessor(isHeaderVPBB(Successor0) ? Successor1
418433
: Successor0);
419-
Region->setExiting(VPBB);
434+
Region->setExiting(VPBB);
435+
}
420436
}
421437

422438
// 2. The whole CFG has been built at this point so all the input Values must

llvm/test/Transforms/LoopVectorize/AArch64/outer_loop_prefer_scalable.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ define void @foo() {
4646
; CHECK-NEXT: [[TMP14:%.*]] = icmp eq <vscale x 4 x i64> [[TMP13]], shufflevector (<vscale x 4 x i64> insertelement (<vscale x 4 x i64> poison, i64 512, i64 0), <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer)
4747
; CHECK-NEXT: [[TMP15:%.*]] = extractelement <vscale x 4 x i1> [[TMP14]], i32 0
4848
; CHECK-NEXT: br i1 [[TMP15]], label [[OUTER_LOOP_LATCH4]], label [[INNER_LOOP1]]
49-
; CHECK: outer_loop_latch4:
49+
; CHECK: vector.latch:
5050
; CHECK-NEXT: [[VEC_PHI5:%.*]] = phi <vscale x 4 x float> [ [[TMP12]], [[INNER_LOOP1]] ]
5151
; CHECK-NEXT: call void @llvm.masked.scatter.nxv4f32.nxv4p0(<vscale x 4 x float> [[VEC_PHI5]], <vscale x 4 x ptr> [[TMP10]], i32 4, <vscale x 4 x i1> shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer))
5252
; CHECK-NEXT: [[TMP16:%.*]] = add nuw nsw <vscale x 4 x i64> [[VEC_IND]], shufflevector (<vscale x 4 x i64> insertelement (<vscale x 4 x i64> poison, i64 1, i64 0), <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer)

llvm/test/Transforms/LoopVectorize/dbg-outer-loop-vect.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define void @foo(ptr %h) !dbg !4 {
2929
; CHECK-NEXT: [[TMP5:%.*]] = icmp eq <4 x i64> [[TMP4]], <i64 5, i64 5, i64 5, i64 5>, !dbg [[DBG25:![0-9]+]]
3030
; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x i1> [[TMP5]], i32 0, !dbg [[DBG26:![0-9]+]]
3131
; CHECK-NEXT: br i1 [[TMP6]], label [[FOR_COND_CLEANUP32]], label [[FOR_COND5_PREHEADER1]], !dbg [[DBG26]]
32-
; CHECK: for.cond.cleanup32:
32+
; CHECK: vector.latch:
3333
; CHECK-NEXT: [[TMP7:%.*]] = add nuw nsw <4 x i64> [[VEC_IND]], <i64 1, i64 1, i64 1, i64 1>, !dbg [[DBG27:![0-9]+]]
3434
; CHECK-NEXT: [[TMP8:%.*]] = icmp eq <4 x i64> [[TMP7]], <i64 23, i64 23, i64 23, i64 23>, !dbg [[DBG28:![0-9]+]]
3535
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4

llvm/test/Transforms/LoopVectorize/outer-loop-vec-phi-predecessor-order.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ define void @test(ptr %src, i64 %n) {
4040
; CHECK-NEXT: [[TMP6:%.*]] = icmp eq <4 x i64> [[TMP5]], [[BROADCAST_SPLAT]]
4141
; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x i1> [[TMP6]], i32 0
4242
; CHECK-NEXT: br i1 [[TMP7]], label [[LOOP_1_LATCH5]], label [[LOOP_2_HEADER1]]
43-
; CHECK: loop.1.latch5:
43+
; CHECK: vector.latch:
4444
; CHECK-NEXT: [[TMP8:%.*]] = add nuw nsw <4 x i64> [[VEC_IND]], <i64 1, i64 1, i64 1, i64 1>
4545
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq <4 x i64> [[TMP8]], [[BROADCAST_SPLAT]]
4646
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4

llvm/test/Transforms/LoopVectorize/outer_loop_hcfg_construction.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ define void @non_outermost_loop_hcfg_construction(i64 %n, ptr %a) {
5151
; CHECK-NEXT: [[TMP6:%.*]] = icmp eq <4 x i64> [[TMP5]], [[BROADCAST_SPLAT3]]
5252
; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x i1> [[TMP6]], i32 0
5353
; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_LOOP_LATCH4]], label [[INNERMOST_LOOP1]]
54-
; CHECK: middle.loop.latch4:
54+
; CHECK: vector.latch:
5555
; CHECK-NEXT: [[TMP8:%.*]] = add nuw nsw <4 x i64> [[VEC_IND]], <i64 1, i64 1, i64 1, i64 1>
5656
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq <4 x i64> [[TMP8]], [[BROADCAST_SPLAT3]]
5757
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
@@ -196,7 +196,7 @@ define void @non_outermost_loop_hcfg_construction_other_loops_at_same_level(i64
196196
; CHECK-NEXT: [[TMP6:%.*]] = icmp eq <4 x i64> [[TMP5]], [[BROADCAST_SPLAT3]]
197197
; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x i1> [[TMP6]], i32 0
198198
; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_LOOP_J0_CLEANUP4]], label [[INNERMOST_LOOP1]]
199-
; CHECK: middle.loop.j0.cleanup4:
199+
; CHECK: vector.latch:
200200
; CHECK-NEXT: [[TMP8:%.*]] = add nuw nsw <4 x i64> [[VEC_IND]], <i64 1, i64 1, i64 1, i64 1>
201201
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq <4 x i64> [[TMP8]], [[BROADCAST_SPLAT3]]
202202
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4

llvm/test/Transforms/LoopVectorize/outer_loop_scalable.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ define void @foo() {
5252
; CHECK-NEXT: [[TMP14:%.*]] = icmp eq <vscale x 4 x i64> [[TMP13]], shufflevector (<vscale x 4 x i64> insertelement (<vscale x 4 x i64> poison, i64 512, i64 0), <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer)
5353
; CHECK-NEXT: [[TMP15:%.*]] = extractelement <vscale x 4 x i1> [[TMP14]], i32 0
5454
; CHECK-NEXT: br i1 [[TMP15]], label [[OUTER_LOOP_LATCH4]], label [[INNER_LOOP1]]
55-
; CHECK: outer_loop_latch4:
55+
; CHECK: vector.latch:
5656
; CHECK-NEXT: [[VEC_PHI5:%.*]] = phi <vscale x 4 x float> [ [[TMP12]], [[INNER_LOOP1]] ]
5757
; CHECK-NEXT: call void @llvm.masked.scatter.nxv4f32.nxv4p0(<vscale x 4 x float> [[VEC_PHI5]], <vscale x 4 x ptr> [[TMP10]], i32 4, <vscale x 4 x i1> shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer))
5858
; CHECK-NEXT: [[TMP16:%.*]] = add nuw nsw <vscale x 4 x i64> [[VEC_IND]], shufflevector (<vscale x 4 x i64> insertelement (<vscale x 4 x i64> poison, i64 1, i64 0), <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer)

llvm/test/Transforms/LoopVectorize/vplan-printing-outer-loop.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ define void @foo(i64 %n) {
3232
; CHECK-NEXT: EMIT branch-on-cond ir<%inner.ec>
3333
; CHECK-NEXT: No successors
3434
; CHECK-NEXT: }
35-
; CHECK-NEXT: Successor(s): outer.latch
35+
; CHECK-NEXT: Successor(s): vector.latch
3636
; CHECK-EMPTY:
37-
; CHECK-NEXT: outer.latch:
37+
; CHECK-NEXT: vector.latch:
3838
; CHECK-NEXT: EMIT ir<%outer.iv.next> = add ir<%outer.iv>, ir<1>
3939
; CHECK-NEXT: EMIT ir<%outer.ec> = icmp ir<%outer.iv.next>, ir<8>
4040
; CHECK-NEXT: EMIT branch-on-cond ir<%outer.ec>

0 commit comments

Comments
 (0)