-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[DirectX] Remove trivially dead functions at linkage finalize #106146
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
+425
−32
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4022447
[DirectX] Remove trivially dead functions at linkage finalize
2335e8c
correct run lines
8320509
Remove test requiring DirectX backend
416b5c0
Eliminate trivially dead functions regardless of inline status
40253bb
Merge remote-tracking branch 'origin/main' into hlsl_remove_internal
21cfc89
Add library DX codegen test
b9c029e
Merge remote-tracking branch 'refs/remotes/origin/main' into hlsl_rem…
5d3953d
Create fully separate library test
4ac12a2
Merge remote-tracking branch 'refs/remotes/origin/main' into hlsl_rem…
ea866f3
Merge remote-tracking branch 'refs/remotes/origin/main' into hlsl_rem…
ba24945
Correct mistaken merge
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
223 changes: 223 additions & 0 deletions
223
llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll
This file contains hidden or 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,223 @@ | ||
| ; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s | ||
| ; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-library %s | FileCheck %s | ||
| ; RUN: llc %s --filetype=asm -o - | FileCheck %s | ||
|
|
||
| target triple = "dxilv1.5-pc-shadermodel6.5-compute" | ||
|
|
||
| ; Confirm that DXILFinalizeLinkage will remove functions that have compatible | ||
| ; linkage and are not called from anywhere. This should be any function that | ||
| ; is not explicitly marked export and is not an entry point. | ||
|
|
||
| ; Has no specified inlining/linking behavior and is uncalled, this should be removed. | ||
| ; CHECK-NOT: define {{.*}}doNothingUncalled | ||
| define void @"?doNothingUncalled@@YAXXZ"() #2 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Alwaysinline and uncalled, this should be removed. | ||
| ; CHECK-NOT: define {{.*}}doAlwaysInlineUncalled | ||
| define void @"?doAlwaysInlineUncalled@@YAXXZ"() #0 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Noinline and uncalled, this should be removed. | ||
| ; CHECK-NOT: define {{.*}}doNoinlineUncalled | ||
| define void @"?doNoinlineUncalled@@YAXXZ"() #4 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; No inlining attribute, internal, and uncalled; this should be removed. | ||
| ; CHECK-NOT: define {{.*}}doInternalUncalled | ||
| define internal void @"?doInternalUncalled@@YAXXZ"() #2 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Alwaysinline, internal, and uncalled; this should be removed. | ||
| ; CHECK-NOT: define {{.*}}doAlwaysInlineInternalUncalled | ||
| define internal void @"?doAlwaysInlineInternalUncalled@@YAXXZ"() #0 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Noinline, internal, and uncalled; this should be removed. | ||
| ; CHECK-NOT: define {{.*}}doNoinlineInternalUncalled | ||
| define internal void @"?doNoinlineInternalUncalled@@YAXXZ"() #4 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Marked external and uncalled, this should become internal and be removed. | ||
| ; CHECK-NOT: define {{.*}}doExternalUncalled | ||
| define external void @"?doExternalUncalled@@YAXXZ"() #2 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Alwaysinline, external and uncalled, this should become internal and be removed. | ||
| ; CHECK-NOT: define {{.*}}doAlwaysInlineExternalUncalled | ||
| define external void @"?doAlwaysInlineExternalUncalled@@YAXXZ"() #0 { | ||
| entry: | ||
hekota marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ret void | ||
| } | ||
|
|
||
| ; Noinline, external and uncalled, this should become internal and be removed. | ||
| ; CHECK-NOT: define {{.*}}doNoinlineExternalUncalled | ||
| define external void @"?doNoinlineExternalUncalled@@YAXXZ"() #4 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; No inlining attribute and called, this should stay. | ||
| ; CHECK: define {{.*}}doNothingCalled | ||
| define void @"?doNothingCalled@@YAXXZ"() #2 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Alwaysinline and called, this should stay. | ||
| ; CHECK: define {{.*}}doAlwaysInlineCalled | ||
| define void @"?doAlwaysInlineCalled@@YAXXZ"() #0 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Noinline and called, this should stay. | ||
| ; CHECK: define {{.*}}doNoinlineCalled | ||
| define void @"?doNoinlineCalled@@YAXXZ"() #4 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; No inlining attribute, internal, and called; this should stay. | ||
| ; CHECK: define {{.*}}doInternalCalled | ||
| define internal void @"?doInternalCalled@@YAXXZ"() #2 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Alwaysinline, internal, and called; this should stay. | ||
| ; CHECK: define {{.*}}doAlwaysInlineInternalCalled | ||
| define internal void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #0 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Noinline, internal, and called; this should stay. | ||
| ; CHECK: define {{.*}}doNoinlineInternalCalled | ||
| define internal void @"?doNoinlineInternalCalled@@YAXXZ"() #4 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Marked external and called, this should become internal and stay. | ||
| ; CHECK: define {{.*}}doExternalCalled | ||
| define external void @"?doExternalCalled@@YAXXZ"() #2 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Always inlined, external and called, this should become internal and stay. | ||
| ; CHECK: define {{.*}}doAlwaysInlineExternalCalled | ||
| define external void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #0 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Noinline, external and called, this should become internal and stay. | ||
| ; CHECK: define {{.*}}doNoinlineExternalCalled | ||
| define external void @"?doNoinlineExternalCalled@@YAXXZ"() #4 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; No inlining attribute and exported, this should stay. | ||
| ; CHECK: define {{.*}}doNothingExported | ||
| define void @"?doNothingExported@@YAXXZ"() #3 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Alwaysinline and exported, this should stay. | ||
| ; CHECK: define {{.*}}doAlwaysInlineExported | ||
| define void @"?doAlwaysInlineExported@@YAXXZ"() #1 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Noinline attribute and exported, this should stay. | ||
| ; CHECK: define {{.*}}doNoinlineExported | ||
| define void @"?doNoinlineExported@@YAXXZ"() #5 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; No inlining attribute, internal, and exported; this should stay. | ||
| ; CHECK: define {{.*}}doInternalExported | ||
| define internal void @"?doInternalExported@@YAXXZ"() #3 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Alwaysinline, internal, and exported; this should stay. | ||
| ; CHECK: define {{.*}}doAlwaysInlineInternalExported | ||
| define internal void @"?doAlwaysInlineInternalExported@@YAXXZ"() #1 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Noinline, internal, and exported; this should stay. | ||
| ; CHECK: define {{.*}}doNoinlineInternalExported | ||
| define internal void @"?doNoinlineInternalExported@@YAXXZ"() #5 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Marked external and exported, this should stay. | ||
| ; CHECK: define {{.*}}doExternalExported | ||
| define external void @"?doExternalExported@@YAXXZ"() #3 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Alwaysinline, external and exported, this should stay. | ||
| ; CHECK: define {{.*}}doAlwaysInlineExternalExported | ||
| define external void @"?doAlwaysInlineExternalExported@@YAXXZ"() #1 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Noinline, external and exported, this should stay. | ||
| ; CHECK: define {{.*}}doNoinlineExternalExported | ||
| define external void @"?doNoinlineExternalExported@@YAXXZ"() #5 { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| ; Entry point function, this should stay. | ||
| ; CHECK: define void @main() | ||
| define void @main() #6 { | ||
| entry: | ||
| call void @"?doNothingCalled@@YAXXZ"() #7 | ||
| call void @"?doAlwaysInlineCalled@@YAXXZ"() #7 | ||
| call void @"?doNoinlineCalled@@YAXXZ"() #7 | ||
| call void @"?doInternalCalled@@YAXXZ"() #7 | ||
| call void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #7 | ||
| call void @"?doNoinlineInternalCalled@@YAXXZ"() #7 | ||
| call void @"?doExternalCalled@@YAXXZ"() #7 | ||
| call void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #7 | ||
| call void @"?doNoinlineExternalCalled@@YAXXZ"() #7 | ||
| ret void | ||
| } | ||
|
|
||
| attributes #0 = { alwaysinline convergent norecurse nounwind } | ||
| attributes #1 = { alwaysinline convergent norecurse nounwind "hlsl.export"} | ||
| attributes #2 = { convergent norecurse nounwind } | ||
| attributes #3 = { convergent norecurse nounwind "hlsl.export"} | ||
| attributes #4 = { convergent noinline norecurse nounwind } | ||
| attributes #5 = { convergent noinline norecurse nounwind "hlsl.export"} | ||
| attributes #6 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } | ||
| attributes #7 = { convergent } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| ; RUN: llc %s --filetype=asm -o - | FileCheck %s | ||
| target triple = "dxil-unknown-shadermodel6.7-library" | ||
|
|
||
| define float @negateF(float %0) { | ||
| define float @negateF(float %0) #0 { | ||
| ; CHECK: %2 = fsub float -0.000000e+00, %0 | ||
| %2 = fneg float %0 | ||
| ret float %2 | ||
| } | ||
|
|
||
| define double @negateD(double %0) { | ||
| define double @negateD(double %0) #0 { | ||
| ; CHECK: %2 = fsub double -0.000000e+00, %0 | ||
| %2 = fneg double %0 | ||
| ret double %2 | ||
| } | ||
|
|
||
| attributes #0 = { convergent norecurse nounwind "hlsl.export"} |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,32 +1,34 @@ | ||
| ; RUN: llc --filetype=asm %s -o - | FileCheck %s | ||
| target triple = "dxil-unknown-shadermodel6.7-library" | ||
|
|
||
| define i64 @test(ptr %p) { | ||
| define i64 @test(ptr %p) #0 { | ||
| %v = load i64, ptr %p | ||
| ret i64 %v | ||
| } | ||
|
|
||
| ; CHECK: define internal i64 @test(ptr %p) { | ||
| ; CHECK: define i64 @test(ptr %p) #0 { | ||
| ; CHECK-NEXT: %v = load i64, ptr %p, align 8 | ||
| ; CHECK-NEXT: ret i64 %v | ||
|
|
||
| define i64 @test2(ptr %p) { | ||
| define i64 @test2(ptr %p) #0 { | ||
| store i64 0, ptr %p | ||
| %v = load i64, ptr %p | ||
| ret i64 %v | ||
| } | ||
|
|
||
| ; CHECK: define internal i64 @test2(ptr %p) { | ||
| ; CHECK: define i64 @test2(ptr %p) #0 { | ||
| ; CHECK-NEXT: store i64 0, ptr %p | ||
| ; CHECK-NEXT: %v = load i64, ptr %p, align 8 | ||
| ; CHECK-NEXT: ret i64 %v | ||
|
|
||
| define i32 @test3(ptr %0) { | ||
| define i32 @test3(ptr %0) #0 { | ||
| %2 = getelementptr i32, ptr %0, i32 4 | ||
| %3 = load i32, ptr %2 | ||
| ret i32 %3 | ||
| } | ||
|
|
||
| ; CHECK: define internal i32 @test3(ptr %0) { | ||
| attributes #0 = { convergent norecurse nounwind "hlsl.export"} | ||
|
|
||
| ; CHECK: define i32 @test3(ptr %0) #0 { | ||
| ; CHECK-NEXT: %2 = getelementptr i32, ptr %0, i32 4 | ||
| ; CHECK-NEXT: %3 = load i32, ptr %2 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.