Skip to content

[DirectX] Running DXILFinalizeLinkage late causes DXILForwardHandleAccesses to fall over in dead code #138180

Closed
@bogner

Description

@bogner

In #136244 we moved the DXILFinalizeLinkage pass later in order to take advantage of the fact that it deletes dead intrinsic declarations after we run DXILLegalize, which can remove all the uses of an intrinsic. However, this is causing problems, as now DXILForwardHandleAccess is running on (now dead) pre-inlined functions, and it isn't able to work out a mapping between globals and handles.

There are a few aspects to the problem here:

  • Should DXILForwardHandleAccess be made to work on code that hasn't yet been inlined?
  • Is DXILFinalizeLinkage in the right place in the pipeline?
  • Should cleaning up dead intrinsic definitions be part of DXILFinalizeLinkage or separate?

I think the answers to these three questions are maybe, no, and separate. We put the intrinsic cleanup code into finalize linkage for two reasons: 1) convenience since the logic is similar, and 2) an assumption that later passes would clean up after themselves. I no longer think that was the right decision, for a couple of reasons:

  1. Dead intrinsics have nothing to do with linkage.
  2. SPIR-V doesn't need to clean up dead intrinsics since it will go through an actual instruction selector, but it does care about linkage
  3. The reason we need to clean up intrinsics is that we're going directly to DXIL from IR. LLVM IR allows these to be present and ignores them if they're unused, and it generally doesn't matter because it isn't the final product.

We should move the cleanup of dead intrinsics way later in the pipeline (likely DXILPrepare) and we should move finalize linkage back to the beginning of the backend pipeline.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions