[llvm] [SPIRV] Let atomic load load pointers (PR #202823)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 09:48:43 PDT 2026


================
@@ -1988,13 +1985,61 @@ bool SPIRVInstructionSelector::selectAtomicLoad(Register ResVReg,
   Register MemSemReg = buildI32Constant(MemSem | StorageClass, I);
 
   MachineIRBuilder MIRBuilder(I);
-  auto AtomicLoad = MIRBuilder.buildInstr(SPIRV::OpAtomicLoad)
-                        .addDef(ResVReg)
-                        .addUse(GR.getSPIRVTypeID(ResType))
-                        .addUse(Ptr)
-                        .addUse(ScopeReg)
-                        .addUse(MemSemReg);
-  AtomicLoad.constrainAllUses(TII, TRI, RBI);
+
+  if (ResType.isTypePtr()) {
+    if (!STI.isPhysicalSPIRV())
+      return diagnoseUnsupported(
+          I, "Lowering to SPIR-V of atomic load is only "
+             "allowed for pointer types for physical addressing model");
+    // If data to load is a pointer type we bitcast the Ptr parameter to pointer
+    // to an integer type of the same size as the pointer size and then generate
+    // OpAtomicLoad the return value of that OpAtomicLoad is an integet that is
+    // converted back to a pointer type using OpConvertUToPtr.
+
+    unsigned PtrSize = GR.getPointerSize();
+    SPIRVTypeInst PtrAsIntSpirvType =
+        GR.getOrCreateSPIRVIntegerType(PtrSize, MIRBuilder);
+    Register PtrToUVal =
+        MRI->createGenericVirtualRegister(LLT::scalar(PtrSize));
+    MRI->setRegClass(PtrToUVal, MRI->getRegClassOrNull(ResVReg));
+    GR.assignSPIRVTypeToVReg(PtrAsIntSpirvType, PtrToUVal, MIRBuilder.getMF());
----------------
fineg74 wrote:

Fixed

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


More information about the llvm-commits mailing list