[llvm-branch-commits] [llvm] [SPIRV] Do not eliminate `OpPointerType` even if unused (PR #182551)

Steven Perron via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 24 06:40:55 PST 2026


s-perron wrote:

> The removal is happening before `validatePtrTypes`? If `validatePtrTypes` ran first, would this still be a problem? Is that something that we could do? If not, why?

For the HLSL code generation. I think we can move this earlier. I don't know about the OpenCL use cases.

The work I put into `validatePtrTypes` is about fixing up the SPIR-V types for cases where the SPIR-V types do not match. Here is how it might work. Before instruction selection a load might look like:

```
%14:fid(s32) = G_LOAD %13:pid(p11)
```

In this case %13 is a pointer to address space 11. The the type pointed to by the pointer must be fully laid out. For a struct this means the pointee type must have offset decorations. However, the type for %14 will not have those decorations. This is a design decision to make it easier to keep track of which types should be used.

If the spir-v is left like that, it will be invalid. The `validatePtrTypes` recognizes these cases, and fixes them up. It will change the return type of the load to match the pointer, and then do an OpCopyLogical to get %14 to match the original type.

I believe it is possible to move this after the post-legalizer and before instruction selection. We just need to update the type in the registery and add the opcopylogical.

https://github.com/llvm/llvm-project/pull/182551


More information about the llvm-branch-commits mailing list