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

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 09:43:25 PDT 2025


================
@@ -2367,6 +2371,29 @@ void SPIRVEmitIntrinsics::applyDemangledPtrArgTypes(IRBuilder<> &B) {
   }
 }
 
+GetElementPtrInst *
+SPIRVEmitIntrinsics::simplifyZeroLengthArrayGepInst(GetElementPtrInst *GEP) {
+  // getelementptr [0 x T], P, 0 (zero), I -> getelementptr T, P, I.
+  // If type is 0-length array and first index is 0 (zero), drop both the
+  // 0-length array type and the first index. This is a common pattern in the
+  // IR, e.g. when using a zero-length array as a placeholder for a flexible
+  // array such as unbound arrays.
+  assert(GEP && "GEP is null");
+  Type *SrcTy = GEP->getSourceElementType();
+  SmallVector<Value *, 8> Indices(GEP->indices());
+  if (SrcTy->isArrayTy() && cast<ArrayType>(SrcTy)->getNumElements() == 0 &&
----------------
Keenuts wrote:

You can do a `ArrayType *AT = dyn_cast<ArrayType>(SrcTy)` once, and then use `!AT` or `AT->getNumElements()`/`AT->getElementType()` instead of casting every time.

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


More information about the llvm-commits mailing list