[clang] [Clang] Fix clang to emit llvm-ir for fadd/fsub atomics (PR #162679)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 17 03:49:08 PDT 2025


================
@@ -3854,7 +3847,16 @@ LValue ScalarExprEmitter::EmitCompoundAssignLValue(
   llvm::PHINode *atomicPHI = nullptr;
   if (const AtomicType *atomicTy = LHSTy->getAs<AtomicType>()) {
     QualType type = atomicTy->getValueType();
-    if (!type->isBooleanType() && type->isIntegerType() &&
+    const bool isFloat = type->isFloatingType();
+    const bool isInteger = type->isIntegerType();
+
+    bool isPowerOfTwo = false;
+    if (isFloat || isInteger) {
+      llvm::Type *IRTy = CGF.ConvertType(type);
+      uint64_t StoreBits = CGF.CGM.getDataLayout().getTypeStoreSizeInBits(IRTy);
+      isPowerOfTwo = llvm::isPowerOf2_64(StoreBits);
+    }
+    if (!type->isBooleanType() && (isInteger || isFloat) && isPowerOfTwo &&
----------------
CarolineConcatto wrote:

I think the problem of not being power of two is just for the floating points. 
Is that correct?
To have minimum changes maybe we should have this test instead:

 if (!type->isBooleanType() && (isInteger || (isPowerOfTwo && isFloat))  && ..

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


More information about the cfe-commits mailing list