[llvm] [SPIRV] Do not use OpTypeRuntimeArray in Kernel env. (PR #149522)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 21 04:54:32 PDT 2025


================
@@ -828,9 +828,11 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeArray(uint32_t NumElems,
          "Invalid array element type");
   SPIRVType *SpvTypeInt32 = getOrCreateSPIRVIntegerType(32, MIRBuilder);
   SPIRVType *ArrayType = nullptr;
-  if (NumElems != 0) {
-    Register NumElementsVReg =
-        buildConstantInt(NumElems, MIRBuilder, SpvTypeInt32, EmitIR);
+  const SPIRVSubtarget &ST =
+      cast<SPIRVSubtarget>(MIRBuilder.getMF().getSubtarget());
+  if (NumElems != 0 || !ST.isShader()) {
+    Register NumElementsVReg = buildConstantInt(
+        NumElems ? NumElems : 1, MIRBuilder, SpvTypeInt32, EmitIR);
----------------
Keenuts wrote:

Is this the correct solution?
I understand `OpRuntimeArray` is not supported for Kernel, but seems weird to silently allow this and generate a 1-element array instead.

Are runtime arrays allowed in OpenCL?
If not, should the compiler refuse to lower a runtime array to Kernel SPIR-V?

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


More information about the llvm-commits mailing list