[llvm] [SPIR-V] Handle constant expression uses of PushConstant globals (PR #193005)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 21 02:11:46 PDT 2026


================
@@ -0,0 +1,27 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | FileCheck %s
+
+%struct.PushConstants = type { <4 x float>, <4 x float>, i32 }
+
+ at push_constants = external hidden addrspace(13) externally_initialized global %struct.PushConstants, align 1
+ at result = external addrspace(1) global i32, align 4
+
+; CHECK-DAG: %[[#INT32:]] = OpTypeInt 32 0
+; CHECK-DAG: %[[#S_T:]] = OpTypeStruct {{.*}} {{.*}} %[[#INT32]]
+; CHECK-DAG: %[[#PTR_PCS_S:]] = OpTypePointer PushConstant %[[#S_T]]
+; CHECK-DAG: %[[#PCS:]] = OpVariable %[[#PTR_PCS_S]] PushConstant
+; CHECK-DAG: %[[#PTR_I32:]] = OpTypePointer PushConstant %[[#INT32]]
+; CHECK-DAG: %[[#INT_2:]] = OpConstant %[[#INT32]] 2
+
+define void @main() #0 {
+entry:
+  ; This is the case where GEP is embedded in the load as a constant expression.
+  ; We want to ensure that it gets lowered correctly to instructions.
+  ; CHECK: %[[#GEP:]] = OpInBoundsAccessChain %[[#PTR_I32]] %[[#PCS]] %[[#INT_2]]
+  ; CHECK: %[[#VAL:]] = OpLoad %[[#INT32]] %[[#GEP]]
+  %0 = load i32, ptr addrspace(13) getelementptr inbounds nuw (%struct.PushConstants, ptr addrspace(13) @push_constants, i32 0, i32 2), align 1
----------------
Keenuts wrote:

Do you reproduce the same issue with the @llvm.structured.gep instruction? Or is the GEP the only instruction that can be inlined this way? If so, can you add a test using this intrinsic?

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


More information about the llvm-commits mailing list