-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DirectX] Eliminate resource global variables from module #114105
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3775e77
[DirectX] Mark buffer load/store as mem read/write
pow2clk d013656
[DirectX] Eliminate resource global variables from module
pow2clk 127d582
Make GV removal more robust add opt dxil-op-lower test
pow2clk 5cc11c7
clang-format
pow2clk 2a18dca
Respond to sundry feedback
pow2clk b9dc4fa
Merge remote-tracking branch 'refs/remotes/origin/main' into elim_res…
pow2clk 1edb01d
restore test for correct memory attributes applied to intrinsics
pow2clk 4ba7021
Merge remote-tracking branch 'refs/remotes/origin/main' into elim_res…
pow2clk 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
; RUN: opt -S -passes='early-cse<memssa>' %s -o %t | ||
; RUN: FileCheck --check-prefixes=CSE,CHECK %s < %t | ||
; Finish compiling to verify that dxil-op-lower removes the globals entirely. | ||
; RUN: opt -mtriple=dxil-pc-shadermodel6.0-compute -S -dxil-op-lower %t -o - | FileCheck --check-prefixes=DXOP,CHECK %s | ||
; RUN: opt -mtriple=dxil-pc-shadermodel6.6-compute -S -dxil-op-lower %t -o - | FileCheck --check-prefixes=DXOP,CHECK %s | ||
; RUN: llc -mtriple=dxil-pc-shadermodel6.0-compute --filetype=asm -o - %t | FileCheck --check-prefixes=DXOP,CHECK %s | ||
; RUN: llc -mtriple=dxil-pc-shadermodel6.6-compute --filetype=asm -o - %t | FileCheck --check-prefixes=DXOP,CHECK %s | ||
|
||
; Ensure that EarlyCSE is able to eliminate unneeded loads of resource globals across typedBufferLoad. | ||
; Also that DXILOpLowering eliminates the globals entirely. | ||
|
||
%"class.hlsl::RWBuffer" = type { target("dx.TypedBuffer", <4 x float>, 1, 0, 0) } | ||
|
||
; DXOP-NOT: @In = global | ||
; DXOP-NOT: @Out = global | ||
@In = global %"class.hlsl::RWBuffer" zeroinitializer, align 4 | ||
@Out = global %"class.hlsl::RWBuffer" zeroinitializer, align 4 | ||
|
||
; CHECK-LABEL define void @main() | ||
define void @main() local_unnamed_addr #0 { | ||
entry: | ||
; DXOP: %In_h.i1 = call %dx.types.Handle @dx.op.createHandle | ||
; DXOP: %Out_h.i2 = call %dx.types.Handle @dx.op.createHandle | ||
%In_h.i = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0) @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0t(i32 0, i32 0, i32 1, i32 0, i1 false) | ||
store target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %In_h.i, ptr @In, align 4 | ||
%Out_h.i = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0) @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0t(i32 4, i32 1, i32 1, i32 0, i1 false) | ||
store target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %Out_h.i, ptr @Out, align 4 | ||
; CSE: call i32 @llvm.dx.flattened.thread.id.in.group() | ||
%0 = call i32 @llvm.dx.flattened.thread.id.in.group() | ||
; CHECK-NOT: load {{.*}} ptr @In | ||
%1 = load target("dx.TypedBuffer", <4 x float>, 1, 0, 0), ptr @In, align 4 | ||
; CSE: call noundef <4 x float> @llvm.dx.typedBufferLoad.v4f32.tdx.TypedBuffer_v4f32_1_0_0t | ||
%2 = call noundef <4 x float> @llvm.dx.typedBufferLoad.v4f32.tdx.TypedBuffer_v4f32_1_0_0t(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %1, i32 %0) | ||
; CHECK-NOT: load {{.*}} ptr @In | ||
%3 = load target("dx.TypedBuffer", <4 x float>, 1, 0, 0), ptr @In, align 4 | ||
%4 = call noundef <4 x float> @llvm.dx.typedBufferLoad.v4f32.tdx.TypedBuffer_v4f32_1_0_0t(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %3, i32 %0) | ||
%add.i = fadd <4 x float> %2, %4 | ||
call void @llvm.dx.typedBufferStore.tdx.TypedBuffer_v4f32_1_0_0t.v4f32(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %Out_h.i, i32 %0, <4 x float> %add.i) | ||
; CHECK: ret void | ||
ret void | ||
} | ||
|
||
; CSE-DAG: declare <4 x float> @llvm.dx.typedBufferLoad.v4f32.tdx.TypedBuffer_v4f32_1_0_0t(target("dx.TypedBuffer", <4 x float>, 1, 0, 0), i32) [[ROAttr:#[0-9]+]] | ||
; CSE-DAG: declare void @llvm.dx.typedBufferStore.tdx.TypedBuffer_v4f32_1_0_0t.v4f32(target("dx.TypedBuffer", <4 x float>, 1, 0, 0), i32, <4 x float>) [[WOAttr:#[0-9]+]] | ||
|
||
attributes #0 = { convergent noinline norecurse "frame-pointer"="all" "hlsl.numthreads"="8,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
|
||
; Just need to split up the DAG searches. | ||
; CSE: attributes #0 | ||
|
||
; CSE-DAG: attributes [[ROAttr]] = { {{.*}} memory(read) } | ||
; CSE-DAG: attributes [[WOAttr]] = { {{.*}} memory(write) } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth leaving a TODO comment around here somewhere that says we should really validate that all of the globals do eventually get removed, since otherwise we'll generate a broken module. Actually implementing that validation can probably be left for later for now, since it would be quite difficult to do locally here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.