-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A function is noreturn if all blocks terminating with a ReturnInst contain a call to a noreturn function. Skip looking at naked functions since there may be asm that returns. This can be further refined in the future by checking unreachable blocks and taking into account recursion. It looks like the attributor pass does this, but that is not yet enabled by default. This seems to help with code size under the new PM since PruneEH does not run under the new PM, missing opportunities to mark some functions noreturn, which in turn doesn't allow simplifycfg to clean up dead code. https://bugs.llvm.org/show_bug.cgi?id=46858. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D93946
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
; RUN: opt < %s -passes='function-attrs' -S | FileCheck %s | ||
|
||
declare i32 @f() | ||
|
||
; CHECK: Function Attrs: noreturn | ||
; CHECK-NEXT: @noreturn() | ||
declare i32 @noreturn() noreturn | ||
|
||
; CHECK: Function Attrs: noreturn | ||
; CHECK-NEXT: @caller() | ||
define i32 @caller() { | ||
%c = call i32 @noreturn() | ||
ret i32 %c | ||
} | ||
|
||
; CHECK: Function Attrs: noreturn | ||
; CHECK-NEXT: @caller2() | ||
define i32 @caller2() { | ||
%c = call i32 @caller() | ||
ret i32 %c | ||
} | ||
|
||
; CHECK: Function Attrs: noreturn | ||
; CHECK-NEXT: @caller3() | ||
define i32 @caller3() { | ||
entry: | ||
br label %end | ||
end: | ||
%c = call i32 @noreturn() | ||
ret i32 %c | ||
} | ||
|
||
; CHECK-NOT: Function Attrs: {{.*}}noreturn | ||
; CHECK: define i32 @caller4() | ||
define i32 @caller4() { | ||
entry: | ||
br label %end | ||
end: | ||
%c = call i32 @f() | ||
ret i32 %c | ||
} | ||
|
||
; CHECK-NOT: Function Attrs: {{.*}}noreturn | ||
; CHECK: @caller5() | ||
; We currently don't handle unreachable blocks. | ||
define i32 @caller5() { | ||
entry: | ||
%c = call i32 @noreturn() | ||
ret i32 %c | ||
unreach: | ||
%d = call i32 @f() | ||
ret i32 %d | ||
} | ||
|
||
; CHECK-NOT: Function Attrs: {{.*}}noreturn | ||
; CHECK: @caller6() | ||
define i32 @caller6() naked { | ||
%c = call i32 @noreturn() | ||
ret i32 %c | ||
} | ||
|
||
; CHECK: Function Attrs: {{.*}}noreturn | ||
; CHECK-NEXT: @alreadynoreturn() | ||
define i32 @alreadynoreturn() noreturn { | ||
unreachable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters