Skip to content
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

[HLSL] Eliminate resource global variables from module #104271

Closed
Tracked by #8 ...
hekota opened this issue Aug 14, 2024 · 0 comments · Fixed by #114105
Closed
Tracked by #8 ...

[HLSL] Eliminate resource global variables from module #104271

hekota opened this issue Aug 14, 2024 · 0 comments · Fixed by #114105
Assignees
Labels
backend:DirectX HLSL HLSL Language Support

Comments

@hekota
Copy link
Member

hekota commented Aug 14, 2024

Global variables that represent shader resources need to be stripped from the final DXIL module, and accesses to resources need to happen locally rather than by round tripping through loads and stores of the global.

We'll need to either write a specific pass to eliminate global accesses to the resource (which needs to happen after inlining), or augment EarlyCSE and/or GVN to do so for us.

For example in this simple shader, we may end up with IR like so before lowering to DXIL ops:

  %In_h.i = tail 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
...
  %1 = tail call noundef <4 x float> @llvm.dx.typedBufferLoad.v4f32.tdx.TypedBuffer_v4f32_1_0_0t(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %In_h.i, i32 %0)
...
  %2 = load target("dx.TypedBuffer", <4 x float>, 1, 0, 0), ptr @In, align 4, !tbaa !4, !noalias !8
  %3 = tail call noundef <4 x float> @llvm.dx.typedBufferLoad.v4f32.tdx.TypedBuffer_v4f32_1_0_0t(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %2, i32 %0)

Here, the store to @In and the load from the same for the argument to typedBufferLoad need to be eliminated. Note that in this case EarlyCSE was able to eliminate the load in the first call to typedBufferLoad but not the second.

@EugeneZelenko EugeneZelenko added HLSL HLSL Language Support and removed new issue labels Aug 14, 2024
@damyanp damyanp moved this to Active in HLSL Support Oct 9, 2024
@bogner bogner moved this from Active to Planning in HLSL Support Oct 21, 2024
@bogner bogner changed the title [HLSL] Strip resource global variables from module [HLSL] Eliminate resource global variables from module Oct 21, 2024
@damyanp damyanp assigned pow2clk and unassigned bogner Oct 21, 2024
@davidcook-msft davidcook-msft moved this from Planning to Active in HLSL Support Oct 22, 2024
pow2clk added a commit to pow2clk/llvm-project that referenced this issue Oct 29, 2024
By giving these intrinsics their appropriate attributes, loads of allocas that are stored on the other side of these calls can be eliminated.

Adds a test that verifies that the unneeded loads can be eliminated and also that the attributes are set properly.

Fixes llvm#104271

This may be the first part of a broader audit of
@damyanp damyanp moved this from Active to Needs Review in HLSL Support Oct 29, 2024
pow2clk added a commit to pow2clk/llvm-project that referenced this issue Oct 30, 2024
By giving these intrinsics their appropriate attributes, loads of globals that are stored on the other side of these calls can be eliminated by the EarlyCSE pass.  Stores to the same globals and the globals themselves require more direct intervention as part of the handleFromBinding lowering.

Adds a test that verifies that the unneeded globals and their uses can be eliminated and also that the attributes are set properly.

Fixes llvm#104271
pow2clk added a commit that referenced this issue Nov 12, 2024
By giving these intrinsics their appropriate attributes, loads of
globals that are stored on the other side of these calls can be
eliminated by the EarlyCSE pass. Stores to the same globals and the
globals themselves require more direct intervention as part of the
create/annotated handle lowering. 

Adds a test that verifies that the unneeded globals and their uses can
be eliminated and also that the attributes are set properly.

Fixes #104271
@github-project-automation github-project-automation bot moved this from Needs Review to Closed in HLSL Support Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX HLSL HLSL Language Support
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

4 participants