[llvm] [SPIR-V] Preserve pointer-to-pointer element type for T*& parameters (PR #203113)

Nick Sarnie via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 11 07:50:41 PDT 2026


================
@@ -1403,8 +1415,18 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
                                  StructuredGEPInst::getPointerOperandIndex()));
   } else if (auto *Ref = dyn_cast<LoadInst>(I)) {
     KnownElemTy = I->getType();
-    if (isUntypedPointerTy(KnownElemTy))
-      return;
+    if (isUntypedPointerTy(KnownElemTy)) {
+      // A T** loaded back from its alloca comes out opaque, dropping a info.
+      // When the load is a pointer-to-pointer, type the alloca as that pointer.
+      Type *LoadedElemTy = GR->findDeducedElementType(I);
+      if (!LoadedElemTy || !isPointerTyOrWrapper(LoadedElemTy))
+        return;
+      Value *Root = Ref->getPointerOperand()->stripPointerCasts();
+      if (!isa<AllocaInst>(Root))
----------------
sarnex wrote:

Do we really only care about `alloca` here? Could a load with a pointer operand from a function arg or something not hit the same problem? Or is it because this is a super clear case where the type is definitely a pointer?

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


More information about the llvm-commits mailing list