[Mlir-commits] [llvm] [mlir] [llvm][OpenMP] Handle complex types in atomic read (PR #111377)

Michael Kruse llvmlistbot at llvm.org
Tue Oct 8 07:16:53 PDT 2024


================
@@ -7832,6 +7832,18 @@ OpenMPIRBuilder::createAtomicRead(const LocationDescription &Loc,
         Builder.CreateLoad(XElemTy, X.Var, X.IsVolatile, "omp.atomic.read");
     XLD->setAtomic(AO);
     XRead = cast<Value>(XLD);
+  } else if (XElemTy->isStructTy()) {
+    LoadInst *OldVal = Builder.CreateLoad(XElemTy, X.Var, "omp.atomic.read");
+    OldVal->setAtomic(AO);
+    const DataLayout &LoadDL = OldVal->getModule()->getDataLayout();
+    unsigned LoadSize =
+        LoadDL.getTypeStoreSize(OldVal->getPointerOperand()->getType());
+    OpenMPIRBuilder::AtomicInfo atomicInfo(
+        &Builder, XElemTy, LoadSize * 8, LoadSize * 8, OldVal->getAlign(),
+        OldVal->getAlign(), true /* UseLibcall */, X.Var);
+    auto AtomicLoadRes = atomicInfo.EmitAtomicLoadLibcall(AO);
----------------
Meinersbur wrote:

Libcalls should only be used if the device does not support `atomicrmw` of that size. E.g. when the struct is only 4 bytes long, emit `atomicrmw` instead of `call __atomic_load`.

I think this is part of the larger issue of handling atomics properly. For the immediate problem, this should work, but I suggest to add a TODO/FIXME comment here.

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


More information about the Mlir-commits mailing list