[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


================
@@ -3150,17 +3152,40 @@ static bool generateAsyncCopy(const SPIRV::IncomingCall *Call,
     Register TypeReg = GR->getSPIRVTypeID(NewType ? NewType : Call->ReturnType);
     unsigned NumArgs = Call->Arguments.size();
     Register EventReg = Call->Arguments[NumArgs - 1];
-    bool Res = MIRBuilder.buildInstr(Opcode)
+    Register NumElemReg = Call->Arguments[2];
+
+    // Untyped pointers use OpUntypedGroupAsyncCopyKHR, which adds an explicit
+    // Element Num Bytes operand.
+    SPIRVTypeInst DestPtrTy = GR->getSPIRVTypeForVReg(Call->Arguments[0]);
+    bool IsUntyped =
+        DestPtrTy && DestPtrTy->getOpcode() == SPIRV::OpTypeUntypedPointerKHR;
+    SPIRVTypeInst SizeTy = GR->getSPIRVTypeForVReg(NumElemReg);
+    Register StrideReg =
+        Call->Arguments.size() > 4
+            ? Call->Arguments[3]
+            : (IsUntyped ? GR->buildConstantInt(1, MIRBuilder, SizeTy,
+                                                /*EmitIR=*/false)
+                         : buildConstantIntReg32(1, MIRBuilder, GR));
+
+    auto MIB = MIRBuilder
+                   .buildInstr(IsUntyped ? SPIRV::OpUntypedGroupAsyncCopyKHR
+                                         : SPIRV::OpGroupAsyncCopy)
                    .addDef(Call->ReturnRegister)
                    .addUse(TypeReg)
                    .addUse(Scope)
                    .addUse(Call->Arguments[0])
-                   .addUse(Call->Arguments[1])
-                   .addUse(Call->Arguments[2])
-                   .addUse(Call->Arguments.size() > 4
-                               ? Call->Arguments[3]
-                               : buildConstantIntReg32(1, MIRBuilder, GR))
-                   .addUse(EventReg);
+                   .addUse(Call->Arguments[1]);
+    if (IsUntyped) {
+      // Element Num Bytes from the deduced element type of dest (or source).
+      unsigned ElemBytes = GR->getDeducedPointeeByteSize(CB.getArgOperand(0));
+      if (!ElemBytes)
+        ElemBytes = GR->getDeducedPointeeByteSize(CB.getArgOperand(1));
+      if (!ElemBytes)
+        ElemBytes = 1;
+      MIB.addUse(GR->buildConstantInt(ElemBytes, MIRBuilder, SizeTy,
+                                      /*EmitIR=*/false));
+    }
+    bool Res = MIB.addUse(NumElemReg).addUse(StrideReg).addUse(EventReg);
----------------
jmmartinez wrote:

`bool Res` looks like a leftover from the past. I think we can remove `Res` (`true` if the `MachineInstr` is not null, so always `true`).

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


More information about the llvm-commits mailing list