Skip to content

Do not remove empty basic blocks which have address taken. #67740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GCEmptyBasicBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool GCEmptyBasicBlocks::runOnMachineFunction(MachineFunction &MF) {
// TODO If a block is an eh pad, or it has address taken, we don't remove
// it. Removing such blocks is possible, but it probably requires a more
// complex logic.
if (MBB->isEHPad() || MBB->isMachineBlockAddressTaken())
if (MBB->isEHPad() || MBB->hasAddressTaken())
continue;
// Skip blocks with real code.
bool HasAnyRealCode = llvm::any_of(*MBB, [](const MachineInstr &MI) {
Expand Down
31 changes: 26 additions & 5 deletions llvm/test/CodeGen/X86/gc-empty-basic-blocks.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
;; This test verifies that -gc-empty-basic-blocks removes empty blocks.
;; This test verifies that -gc-empty-basic-blocks removes regular empty blocks
;; but does not remove empty blocks which have their address taken.
; RUN: llc < %s -mtriple=x86_64 -O0 -gc-empty-basic-blocks | FileCheck %s

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

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

2: ; preds = %1
%3 = call i32 @bar()
%3 = call i32 @baz()
br label %4

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

; CHECK-NOT: %empty_block
; CHECK-NOT: .LBB0_2
; CHECK-NOT: %empty_block
; CHECK-NOT: .LBB0_2

4: ; preds = %2, %empty_block
ret void
Expand All @@ -30,4 +32,23 @@ empty_block: ; preds = %1

}

declare i32 @bar()
;; This function has an empty block which has its address taken. Check that it
;; is not removed by -gc-empty-basic-blocks.
define void @bar(i1 zeroext %0) nounwind {
entry:
%1 = select i1 %0, ptr blockaddress(@bar, %empty_block), ptr blockaddress(@bar, %bb2) ; <ptr> [#uses=1]
indirectbr ptr %1, [label %empty_block, label %bb2]

; CHECK-LABEL: bar:

empty_block: ; preds = %entry
unreachable

; CHECK-LABEL: .LBB1_1: # %empty_block

bb2: ; preds = %entry
%2 = call i32 @baz()
ret void
}

declare i32 @baz()