[llvm] [SPIR-V] Implement SPV_KHR_untyped_pointers extension (PR #201233)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 08:19:29 PDT 2026


================
@@ -2027,14 +2065,22 @@ static void buildSRetInst(unsigned Opcode, Register SRetReg, Register Op1Reg,
 //     OpStore RetVariable Res
 static bool generateICarryBorrowInst(const SPIRV::IncomingCall *Call,
                                      MachineIRBuilder &MIRBuilder,
-                                     SPIRVGlobalRegistry *GR) {
+                                     SPIRVGlobalRegistry *GR,
+                                     const CallBase &CB) {
   const SPIRV::DemangledBuiltin *Builtin = Call->Builtin;
   unsigned Opcode =
       SPIRV::lookupNativeBuiltin(Builtin->Name, Builtin->Set)->Opcode;
 
   Register SRetReg = Call->Arguments[0];
   SPIRVTypeInst PtrRetType = GR->getSPIRVTypeForVReg(SRetReg);
   SPIRVTypeInst RetType = GR->getPointeeType(PtrRetType);
+  if (!RetType) {
+    // For an untyped sret pointer, recover the result type from the deduced
+    // type.
+    if (Type *ElemTy = GR->findDeducedElementType(CB.getArgOperand(0)))
+      RetType = GR->getOrCreateSPIRVType(
+          ElemTy, MIRBuilder, SPIRV::AccessQualifier::ReadWrite, false);
+  }
   if (!RetType)
     report_fatal_error("The first parameter must be a pointer");
----------------
jmmartinez wrote:

I think we should try to refactor these SRet deduction calls into a single function; but I'm not sure I see an obvious pattern across all of them.

At least these 3 look similar: `generateICarryBorrowInst`, `generateMulExtendedInst` and `buildAPFixedPointInst`.

And maybe `buildNDRange`.

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


More information about the llvm-commits mailing list