[llvm] [SPIR-V] Deduce pointee type for all global variables, not only initialized ones (PR #202047)

Julian Klappenbach via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 04:22:18 PDT 2026


================
@@ -2553,12 +2553,23 @@ void SPIRVEmitIntrinsics::processGlobalValue(GlobalVariable &GV,
   if (!shouldEmitIntrinsicsForGlobalValue(GVUsers, GV, CurrF))
     return;
 
+  // Deduce and record the variable's pointee type from its declared value type,
+  // for EVERY global — not only hasInitializer() ones. A global variable's type
+  // is concrete and authoritative; recording it here (this runs before the
+  // use-based forward pass) keeps an undef-initialized, non-constant aggregate
+  // — e.g. a Workgroup `[N x T]` shared tile — from being collapsed to its
+  // element type by flat element-typed GEP accesses. Without this,
+  // hasInitializer() excludes such globals (undef + non-constant), the
+  // variable's type is inferred from a `getelementptr T, ...` use as scalar
+  // `T`, the array-to-pointer-decay GEP rewrite in visitGetElementPtrInst is
+  // skipped (its ArrayType check fails), and under Logical SPIR-V the dynamic
+  // index is dropped — every invocation then accesses element 0. (Result
+  // ignored: TypedPointerType isn't expressible in general LLVM IR; it is
+  // stored in the Global Registry.)
----------------
jklappenbach wrote:

Trimmed down.

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


More information about the llvm-commits mailing list