Skip to content

Commit 5da571f

Browse files
committed
Do not remove empty basic blocks which have address taken.
1 parent b855ae9 commit 5da571f

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

llvm/lib/CodeGen/GCEmptyBasicBlocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool GCEmptyBasicBlocks::runOnMachineFunction(MachineFunction &MF) {
5858
// TODO If a block is an eh pad, or it has address taken, we don't remove
5959
// it. Removing such blocks is possible, but it probably requires a more
6060
// complex logic.
61-
if (MBB->isEHPad() || MBB->isMachineBlockAddressTaken())
61+
if (MBB->isEHPad() || MBB->hasAddressTaken())
6262
continue;
6363
// Skip blocks with real code.
6464
bool HasAnyRealCode = llvm::any_of(*MBB, [](const MachineInstr &MI) {
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
;; This test verifies that -gc-empty-basic-blocks removes empty blocks.
1+
;; This test verifies that -gc-empty-basic-blocks removes regular empty blocks
2+
;; but does not remove empty blocks which have their address taken.
23
; RUN: llc < %s -mtriple=x86_64 -O0 -gc-empty-basic-blocks | FileCheck %s
34

5+
;; This function has a regular empty block.
46
define void @foo(i1 zeroext %0) nounwind {
57
br i1 %0, label %2, label %empty_block
68

@@ -10,7 +12,7 @@ define void @foo(i1 zeroext %0) nounwind {
1012
; CHECK-NEXT: jmp .LBB0_3
1113

1214
2: ; preds = %1
13-
%3 = call i32 @bar()
15+
%3 = call i32 @baz()
1416
br label %4
1517

1618
; CHECK-LABEL: .LBB0_1:
@@ -19,8 +21,8 @@ define void @foo(i1 zeroext %0) nounwind {
1921
empty_block: ; preds = %1
2022
unreachable
2123

22-
; CHECK-NOT: %empty_block
23-
; CHECK-NOT: .LBB0_2
24+
; CHECK-NOT: %empty_block
25+
; CHECK-NOT: .LBB0_2
2426

2527
4: ; preds = %2, %empty_block
2628
ret void
@@ -30,4 +32,23 @@ empty_block: ; preds = %1
3032

3133
}
3234

33-
declare i32 @bar()
35+
;; This function has an empty block which has its address taken. Check that it
36+
;; is not removed by -gc-empty-basic-blocks.
37+
define void @bar(i1 zeroext %0) nounwind {
38+
entry:
39+
%1 = select i1 %0, ptr blockaddress(@bar, %empty_block), ptr blockaddress(@bar, %bb2) ; <ptr> [#uses=1]
40+
indirectbr ptr %1, [label %empty_block, label %bb2]
41+
42+
; CHECK-LABEL: bar:
43+
44+
empty_block: ; preds = %entry
45+
unreachable
46+
47+
; CHECK-LABEL: .LBB1_1: # %empty_block
48+
49+
bb2: ; preds = %entry
50+
%2 = call i32 @baz()
51+
ret void
52+
}
53+
54+
declare i32 @baz()

0 commit comments

Comments
 (0)