@@ -7836,7 +7836,7 @@ OpenMPIRBuilder::createAtomicRead(const LocationDescription &Loc,
78367836 " OMP Atomic expects a pointer to target memory" );
78377837 Type *XElemTy = X.ElemTy ;
78387838 assert ((XElemTy->isFloatingPointTy () || XElemTy->isIntegerTy () ||
7839- XElemTy->isPointerTy ()) &&
7839+ XElemTy->isPointerTy () || XElemTy-> isStructTy () ) &&
78407840 " OMP atomic read expected a scalar type" );
78417841
78427842 Value *XRead = nullptr ;
@@ -7846,6 +7846,20 @@ OpenMPIRBuilder::createAtomicRead(const LocationDescription &Loc,
78467846 Builder.CreateLoad (XElemTy, X.Var , X.IsVolatile , " omp.atomic.read" );
78477847 XLD->setAtomic (AO);
78487848 XRead = cast<Value>(XLD);
7849+ } else if (XElemTy->isStructTy ()) {
7850+ // FIXME: Add checks to ensure __atomic_load is emitted iff the
7851+ // target does not support `atomicrmw` of the size of the struct
7852+ LoadInst *OldVal = Builder.CreateLoad (XElemTy, X.Var , " omp.atomic.read" );
7853+ OldVal->setAtomic (AO);
7854+ const DataLayout &LoadDL = OldVal->getModule ()->getDataLayout ();
7855+ unsigned LoadSize =
7856+ LoadDL.getTypeStoreSize (OldVal->getPointerOperand ()->getType ());
7857+ OpenMPIRBuilder::AtomicInfo atomicInfo (
7858+ &Builder, XElemTy, LoadSize * 8 , LoadSize * 8 , OldVal->getAlign (),
7859+ OldVal->getAlign (), true /* UseLibcall */ , X.Var );
7860+ auto AtomicLoadRes = atomicInfo.EmitAtomicLoadLibcall (AO);
7861+ XRead = AtomicLoadRes.first ;
7862+ OldVal->eraseFromParent ();
78497863 } else {
78507864 // We need to perform atomic op as integer
78517865 IntegerType *IntCastTy =
0 commit comments