Skip to content

[SPIR-V] Non-logical pointer generated following an ptrcast #124928

@Keenuts

Description

@Keenuts

Logical SPIR-V is not allowing pointer cast after an OpAccessChain.

Given this LLVM IR:

define internal spir_func void @baz(ptr addrspace(10) %a, i64 %b) {
  %index = getelementptr <4 x i32>, ptr addrspace(10) %a, i64 %b
  %load = load <3 x i32>, ptr addrspace(10) %index, align 4
  ret void
}

In OpenCL SPIR-V, the following instructions would be generated:

    %index_1 = OpAccessChain %_ptr_Private_v4uint %a_1
         %28 = OpBitcast %_ptr_Private_v3uint %index_1
    %loadv_1 = OpLoad %v3uint %28 Aligned 4

This is not allowed in logical SPIR-V.

For this specific case, what we'd need is to load the initial <4 x i32>, then OpCompositeExtract and then OpCompositeConstruct.

If the types were of the same bit-size, we could to the OpBitcast, but on the value after the load.
For other types of cast, we might have to handle this differently (loading the initial member of a struct for ex).

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions