Skip to content

Commit a96444a

Browse files
committed
[VPlan] Remove dead exit block handling code in HCFGBuilder.
The mapping of IR ExitBB to a VPBB isn't used. It also sets an incorrect VPBB for the ExitBB; the regions successor is the middle block, no the exit block. It also unnecessarily triggers an assertion after 38376de.
1 parent 5450954 commit a96444a

File tree

2 files changed

+90
-18
lines changed

2 files changed

+90
-18
lines changed

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -366,24 +366,6 @@ void PlainCFGBuilder::buildPlainCFG(
366366
// latter.
367367
BB2VPBB[ThePreheaderBB] = VectorPreheaderVPBB;
368368
Loop2Region[LI->getLoopFor(TheLoop->getHeader())] = TheRegion;
369-
BasicBlock *ExitBB = TheLoop->getUniqueExitBlock();
370-
if (!ExitBB) {
371-
// If there is no unique exit block, we must exit via the latch. This exit
372-
// is mapped to the middle block in the input plan.
373-
BasicBlock *Latch = TheLoop->getLoopLatch();
374-
auto *Br = cast<BranchInst>(Latch->getTerminator());
375-
if (TheLoop->contains(Br->getSuccessor(0))) {
376-
assert(!TheLoop->contains(Br->getSuccessor(1)) &&
377-
"latch must exit the loop");
378-
ExitBB = Br->getSuccessor(1);
379-
} else {
380-
assert(!TheLoop->contains(Br->getSuccessor(0)) &&
381-
"latch must exit the loop");
382-
ExitBB = Br->getSuccessor(0);
383-
}
384-
}
385-
assert(ExitBB && "Must have a unique exit block or also exit via the latch.");
386-
BB2VPBB[ExitBB] = cast<VPBasicBlock>(TheRegion->getSingleSuccessor());
387369

388370
// The existing vector region's entry and exiting VPBBs correspond to the loop
389371
// header and latch.

llvm/test/Transforms/LoopVectorize/loop-form.ll

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,3 +1321,93 @@ exit:
13211321
ret i32 %accum
13221322
}
13231323

1324+
define i16 @multiple_exit_none_via_latch(ptr %dst, i64 %x) {
1325+
; CHECK-LABEL: @multiple_exit_none_via_latch(
1326+
; CHECK-NEXT: entry:
1327+
; CHECK-NEXT: [[UMIN:%.*]] = call i64 @llvm.umin.i64(i64 [[X:%.*]], i64 100)
1328+
; CHECK-NEXT: [[TMP0:%.*]] = add nuw nsw i64 [[UMIN]], 1
1329+
; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 [[TMP0]], 2
1330+
; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1331+
; CHECK: vector.ph:
1332+
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP0]], 2
1333+
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
1334+
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i64 2, i64 [[N_MOD_VF]]
1335+
; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP0]], [[TMP2]]
1336+
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
1337+
; CHECK: vector.body:
1338+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1339+
; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 0
1340+
; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[INDEX]], 1
1341+
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, ptr [[DST:%.*]], i64 [[TMP3]]
1342+
; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 [[TMP4]]
1343+
; CHECK-NEXT: store i64 0, ptr [[TMP5]], align 8
1344+
; CHECK-NEXT: store i64 0, ptr [[TMP6]], align 8
1345+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
1346+
; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1347+
; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP24:![0-9]+]]
1348+
; CHECK: middle.block:
1349+
; CHECK-NEXT: br label [[SCALAR_PH]]
1350+
; CHECK: scalar.ph:
1351+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1352+
; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
1353+
; CHECK: loop.header:
1354+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
1355+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 [[IV]]
1356+
; CHECK-NEXT: store i64 0, ptr [[GEP]], align 8
1357+
; CHECK-NEXT: [[CMP120:%.*]] = icmp slt i64 [[IV]], 100
1358+
; CHECK-NEXT: br i1 [[CMP120]], label [[LOOP_THEN:%.*]], label [[EXIT_2:%.*]]
1359+
; CHECK: loop.then:
1360+
; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i64 [[IV]], [[X]]
1361+
; CHECK-NEXT: br i1 [[CMP3]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
1362+
; CHECK: loop.latch:
1363+
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
1364+
; CHECK-NEXT: br label [[LOOP_HEADER]], !llvm.loop [[LOOP25:![0-9]+]]
1365+
; CHECK: exit.1:
1366+
; CHECK-NEXT: ret i16 0
1367+
; CHECK: exit.2:
1368+
; CHECK-NEXT: ret i16 1
1369+
;
1370+
; TAILFOLD-LABEL: @multiple_exit_none_via_latch(
1371+
; TAILFOLD-NEXT: entry:
1372+
; TAILFOLD-NEXT: br label [[LOOP_HEADER:%.*]]
1373+
; TAILFOLD: loop.header:
1374+
; TAILFOLD-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
1375+
; TAILFOLD-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[DST:%.*]], i64 [[IV]]
1376+
; TAILFOLD-NEXT: store i64 0, ptr [[GEP]], align 8
1377+
; TAILFOLD-NEXT: [[CMP120:%.*]] = icmp slt i64 [[IV]], 100
1378+
; TAILFOLD-NEXT: br i1 [[CMP120]], label [[LOOP_THEN:%.*]], label [[EXIT_2:%.*]]
1379+
; TAILFOLD: loop.then:
1380+
; TAILFOLD-NEXT: [[CMP3:%.*]] = icmp ne i64 [[IV]], [[X:%.*]]
1381+
; TAILFOLD-NEXT: br i1 [[CMP3]], label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
1382+
; TAILFOLD: loop.latch:
1383+
; TAILFOLD-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
1384+
; TAILFOLD-NEXT: br label [[LOOP_HEADER]]
1385+
; TAILFOLD: exit.1:
1386+
; TAILFOLD-NEXT: ret i16 0
1387+
; TAILFOLD: exit.2:
1388+
; TAILFOLD-NEXT: ret i16 1
1389+
;
1390+
entry:
1391+
br label %loop.header
1392+
1393+
loop.header:
1394+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
1395+
%gep = getelementptr inbounds i32, ptr %dst, i64 %iv
1396+
store i64 0, ptr %gep
1397+
%cmp120 = icmp slt i64 %iv, 100
1398+
br i1 %cmp120, label %loop.then, label %exit.2
1399+
1400+
loop.then:
1401+
%cmp3 = icmp ne i64 %iv, %x
1402+
br i1 %cmp3, label %loop.latch, label %exit.1
1403+
1404+
loop.latch:
1405+
%iv.next = add i64 %iv, 1
1406+
br label %loop.header
1407+
1408+
exit.1:
1409+
ret i16 0
1410+
1411+
exit.2:
1412+
ret i16 1
1413+
}

0 commit comments

Comments
 (0)