[llvm] [SPIR-V] Add OpUntypedVariableLengthArrayINTEL support for SPV_INTEL_variable_length_array (PR #224756)
Viktoria Maximova via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 07:57:43 PDT 2026
================
@@ -7043,11 +7043,30 @@ bool SPIRVInstructionSelector::selectAllocaArray(Register ResVReg,
// there was an allocation size parameter to the allocation instruction
// that is not 1
MachineBasicBlock &BB = *I.getParent();
- BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpVariableLengthArrayINTEL))
- .addDef(ResVReg)
- .addUse(GR.getSPIRVTypeID(ResType))
- .addUse(I.getOperand(2).getReg())
- .constrainAllUses(TII, TRI, RBI);
+
+ bool UseUntypedPointers =
+ ResType->getOpcode() == SPIRV::OpTypeUntypedPointerKHR;
+ unsigned Opcode = UseUntypedPointers
+ ? SPIRV::OpUntypedVariableLengthArrayINTEL
+ : SPIRV::OpVariableLengthArrayINTEL;
+
+ auto MIB = BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode))
+ .addDef(ResVReg)
+ .addUse(GR.getSPIRVTypeID(ResType));
+
+ // OpUntypedVariableLengthArrayINTEL takes an explicit Element Type <id>
+ // right after the result type
+ if (UseUntypedPointers) {
+ SPIRVTypeInst ElementType = GR.getUntypedPtrElementType(ResVReg);
+ assert(ElementType &&
+ "untyped variable length array result must have a recorded element "
+ "type");
----------------
vmaksimo wrote:
`getUntypedPtrElementType()` returns null if no element type was recorded for this register, and in release builds the assert is compiled out, so the null goes straight into `getSPIRVTypeID()`. `selectFrameIndex` handles the same case with a diagnostic; could we do the same here?
```suggestion
if (!ElementType)
return diagnoseUnsupported(I, "could not deduce the element type of an "
"untyped variable length array");
```
https://github.com/llvm/llvm-project/pull/224756
More information about the llvm-commits
mailing list