[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:12:58 PST 2026


================
@@ -11781,6 +11781,38 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createAtomicCapture(
   return Builder.saveIP();
 }
 
+/// The integer type used to perform an atomic operation on a value of type
+/// \p FPTy: its allocation size, not its scalar width (x86_fp80 is 80 bits in
+/// 16 bytes, and an i80 atomic is not a legal power-of-two access).
+static IntegerType *getAtomicIntTypeForFP(Type *FPTy, const DataLayout &DL) {
+  return IntegerType::get(FPTy->getContext(), DL.getTypeAllocSizeInBits(FPTy));
+}
+
+/// Reinterpret \p V as \p IntTy, zero-filling any padding bits.
+static Value *castFPToAtomicInt(IRBuilderBase &Builder, const DataLayout &DL,
+                                Value *V, IntegerType *IntTy) {
+  unsigned ValueBits = V->getType()->getPrimitiveSizeInBits();
+  if (ValueBits == IntTy->getBitWidth())
+    return Builder.CreateBitCast(V, IntTy);
+  // zext/trunc match the memory layout only on little-endian targets, which
+  // are the only ones with padded FP types.
+  assert(DL.isLittleEndian() && "padded FP type on a big-endian target");
+  Value *Bits =
+      Builder.CreateBitCast(V, IntegerType::get(V->getContext(), ValueBits));
+  return Builder.CreateZExt(Bits, IntTy);
----------------
akash-manna-sky wrote:

Done. A padded FP type is now loaded, only its value bits are compared, and the loaded pattern is the cmpxchg expected value (retried if x changed), so padding never takes part. Same code for 5.1 and 5.2, matching GCC. Added a `-fopenmp-version=52` RUN line and a libomp runtime test with the `zero/0xa5` padding cases.


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


More information about the cfe-commits mailing list