[llvm] [SPIR-V] Add OpUntypedVariableLengthArrayINTEL support for SPV_INTEL_variable_length_array (PR #224756)
Qi Ye via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 10:49:08 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");
----------------
Qi-Ye-079 wrote:
Use assert here because I don't think the `ElementType==nullptr` case is reachable. It's translated from `alloca` which always carries the element type, so the `ElementType` should always be known. This should be an invariant pre-condition that always hold. I'm not sure if VLA is allowed in shaders, but both `SPV_INTEL_variable_length_array` and `SPV_KHR_untyped_pointers` are defined for OpenCL env only in SPIRVSymbolicOperands.td, so we don't need to consider shader env here.
About the `diagnoseUnsupported` in `selectFrameIndex`, I think it's never reachable either, and there's no test to cover it.
https://github.com/llvm/llvm-project/pull/224756
More information about the llvm-commits
mailing list