[llvm] [hlsl][spirv] Add late pass in spirv backend to remove dead resources (PR #225270)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 00:26:39 PDT 2026
rj123-nv wrote:
> > @bogner @hekota, does that match where you want resource legalization to go?
>
> I think there are 2 parts of this:
>
> 1. Removal of unused resources: for DXIL this happens in the `DXILRemoveUnusedResources` pass. It removes any calls to `dx_resource_handlefrom{implicit}binding` whose return value is either not used at all, or it is saved to a global variable that does not have external linkage and is not used anywhere else in the module. In the latter case the global variable is removed as well ([[DirectX] Add DXILRemoveUnusedResources pass #200965](https://github.com/llvm/llvm-project/pull/200965)).
>
> 2. Removal of resource global variables after moving the handles to SSA values. This happens during DXIL lowering:(https://github.com/llvm/llvm-project/blob/afca127bbb62fa30e3734ea149618c2b92bffb6b/llvm/lib/Target/DirectX/DXILOpLowering.cpp#L252
> )
Thanks for explaining. I'm still trying to wrap my head around all the implications, although they seem a bit redundant, I see (2) was implemented before (1), and (2) has this comment:
// TODO: We should verify that all the globals get removed.
// It's expected we'll need a custom pass in the future that will eliminate
// the need for this here.
SPIRVRemoveUnusedResources seems like a combo of both, which I think you're also saying, Because I need to also remove the gvar even if the resource_* intrinsic has other users, which the frag_ep1 test shows.
I realized though I forgot to check if the resource_* CI can be DCE'd after removing the stores, I will add that next, it's not applicable to the current test.
> In both cases the globals are found through the `dx_resource_handlefrom{implicit}binding` calls, so it only applies to resources.
Yes, I can also test for only stores where value operand is one of these resource_* intrinsics (see 2nd commit). I believe that fixes all the test failures. It seems many of the existing tests rely on a setup where they write to some random gvar which the pass was breaking expected output, I don't think it was wrong semantically to remove these (need to verify this part more closely though)
Instead of visiting globals we could visit the IntrinsicInst's like the DXIL pass, although that seems a bit slower.
https://github.com/llvm/llvm-project/pull/225270
More information about the llvm-commits
mailing list