[llvm] [SPIRV] Do not use OpTypeRuntimeArray in Kernel env. (PR #149522)
Dmitry Sidorov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 05:47:33 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);
----------------
MrSidims wrote:
> Is this the correct solution?
That's interesting Q. I lean to say: yes. This replacement will legalize few GEPs that would be UB otherwise, but since they were already UB - such replacement should be fine.
> Are runtime arrays allowed in OpenCL?
> If not, should the compiler refuse to lower a runtime array to Kernel SPIR-V?
OpenCL allows unbounded arrays as kernel parameters and I believe GEP to unbound array kernel argument happens in the test provided by @maarquitos14 (though I'm having troubles to get a similar IR in my experiments).
https://github.com/llvm/llvm-project/pull/149522
More information about the llvm-commits
mailing list