[clang] [llvm] [SPIRV] Rewrite phis of resource pointers as phis of indices (PR #246509)
Diego Novillo via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 30 07:51:00 PST 2026
dnovillo wrote:
> The middleend already performs this exact rewrite, see `simplifycfg<sink-common-insts>` [...] Can we settle which is right?
Yeah, I checked this. Without `convergent` SimplifyCFG does produce the `select` of indices. I agree it's an optimization blocker, not a semantic requirement. But today it's the only thing enforcing that constraint. I traced back the history of this and found the following:
- It was dropped in #193593, but that allowed SimplifyCFG to merge accesses to two different buffers (#201901). So, it was put back in #205433.
- Token-like handle types, which would forbid a phi of handles, were dropped for DXIL in #222130.
- On SPIR-V, a non-convergent `getpointer` turns `A[i]` and `B[i]` on the two sides of a branch into a `select` of handles, which the backend rejects.
Even with `convergent`, InstCombine's `foldPHIArgLoadIntoPHI` builds the pointer phi without moving `getpointer`, so the backend has to undo it, as DirectX does in #211687 (#207852). Moving the call to the join block is fine here, since the pass runs after `StripConvergenceIntrinsics` and keeps the handle.
@hekota, @inbelic, did I get the sequence of events right? Is this roughly why `getpointer` is marked convergent?
> In general I'd like not to re-invent things already existing elsewhere in the project.
Agreed. The DirectX version works on `dx.resource.getpointer` inside `DXILResourceAccess`, and AMDGPU splits fat-pointer phis for a different reason, so I couldn't share either without making one backend depend on another. If there's a target-independent utility for this, I'm happy to switch to it.
https://github.com/llvm/llvm-project/pull/246509
More information about the cfe-commits
mailing list