[clang] [llvm] [openmp] [OMPIRBuilder] Fix atomic compare `==` on `x86-64` long double (PR #226567)

Akash Manna via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 5 23:16:43 PST 2026


================
@@ -11935,16 +11967,16 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createAtomicCompare(
         Builder.SetInsertPoint(&*ExitBB->getFirstNonPHIIt());
       }
 
-      OldValue = Builder.CreateBitCast(OldIntPHI, X.ElemTy,
-                                       X.Var->getName() + ".atomic.old.fp");
+      OldValue = castAtomicIntToFP(Builder, DL, OldIntPHI, X.ElemTy,
+                                   X.Var->getName() + ".atomic.old.fp");
       SuccessOrFail = SuccessPHI;
     } else {
       AtomicCmpXchgInst *Result = nullptr;
+      const DataLayout &DL = M.getDataLayout();
       if (!IsInteger) {
-        IntegerType *IntCastTy =
-            IntegerType::get(M.getContext(), X.ElemTy->getScalarSizeInBits());
-        Value *EBCast = Builder.CreateBitCast(E, IntCastTy);
-        Value *DBCast = Builder.CreateBitCast(D, IntCastTy);
+        IntegerType *IntCastTy = getAtomicIntTypeForFP(X.ElemTy, DL);
+        Value *EBCast = castFPToAtomicInt(Builder, DL, E, IntCastTy);
+        Value *DBCast = castFPToAtomicInt(Builder, DL, D, IntCastTy);
         Result = Builder.CreateAtomicCmpXchg(X.Var, EBCast, DBCast,
                                              MaybeAlign(), AO, Failure);
----------------
akash-manna-sky wrote:

Done. `AtomicOpValue` now carries the alignment of x, v and r, filled by Clang and used on the load, `cmpxchgs`, `atomicrmw` and captured stores. The packed member gets align 1, which `AtomicExpand` lowers to the `__atomic_compare_exchange libcall`. Added the packed long double `codegen` test and the `HandleFPNegZero` unit test with an `x86_fp80` aligned to 1. The other `create*` entry points don't use the alignment yet; Clang doesn't call them, so that's a follow-up.


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


More information about the cfe-commits mailing list