[llvm] AtomicExpand: Preserve metadata when bitcasting fp atomicrmw xchg (PR #115240)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 16:08:11 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/115240.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/AtomicExpandPass.cpp (+1) 
- (modified) llvm/test/Transforms/AtomicExpand/X86/expand-atomic-xchg-fp.ll (+22) 


``````````diff
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index 1471e3d7cbc29d..439236633c41bc 100644
--- a/llvm/lib/CodeGen/AtomicExpandPass.cpp
+++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp
@@ -498,6 +498,7 @@ AtomicExpandImpl::convertAtomicXchgToIntegerType(AtomicRMWInst *RMWI) {
                                           RMWI->getAlign(), RMWI->getOrdering(),
                                           RMWI->getSyncScopeID());
   NewRMWI->setVolatile(RMWI->isVolatile());
+  copyMetadataForAtomic(*NewRMWI, *RMWI);
   LLVM_DEBUG(dbgs() << "Replaced " << *RMWI << " with " << *NewRMWI << "\n");
 
   Value *NewRVal = RMWI->getType()->isPointerTy()
diff --git a/llvm/test/Transforms/AtomicExpand/X86/expand-atomic-xchg-fp.ll b/llvm/test/Transforms/AtomicExpand/X86/expand-atomic-xchg-fp.ll
index c88671e3bb407f..2341eb05c568c2 100644
--- a/llvm/test/Transforms/AtomicExpand/X86/expand-atomic-xchg-fp.ll
+++ b/llvm/test/Transforms/AtomicExpand/X86/expand-atomic-xchg-fp.ll
@@ -36,3 +36,25 @@ define double @atomic_xchg_f64_as1(ptr addrspace(1) %ptr) nounwind {
   %result = atomicrmw xchg ptr addrspace(1) %ptr, double 4.0 seq_cst
   ret double %result
 }
+
+define double @atomic_xchg_f64_preserve_md(ptr %ptr) nounwind {
+; CHECK-LABEL: @atomic_xchg_f64_preserve_md(
+; CHECK-NEXT:    [[TMP1:%.*]] = load i64, ptr [[PTR:%.*]], align 8, !mmra [[META0:![0-9]+]]
+; CHECK-NEXT:    br label [[ATOMICRMW_START:%.*]]
+; CHECK:       atomicrmw.start:
+; CHECK-NEXT:    [[LOADED:%.*]] = phi i64 [ [[TMP1]], [[TMP0:%.*]] ], [ [[NEWLOADED:%.*]], [[ATOMICRMW_START]] ]
+; CHECK-NEXT:    [[TMP2:%.*]] = cmpxchg ptr [[PTR]], i64 [[LOADED]], i64 4616189618054758400 seq_cst seq_cst, align 8, !mmra [[META0]]
+; CHECK-NEXT:    [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP2]], 1
+; CHECK-NEXT:    [[NEWLOADED]] = extractvalue { i64, i1 } [[TMP2]], 0
+; CHECK-NEXT:    br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
+; CHECK:       atomicrmw.end:
+; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i64 [[NEWLOADED]] to double
+; CHECK-NEXT:    ret double [[TMP3]]
+;
+  %result = atomicrmw xchg ptr %ptr, double 4.000000e+00 seq_cst, align 8, !mmra !0
+  ret double %result
+}
+
+!0 = !{!1, !2}
+!1 = !{!"foo", !"bar"}
+!2 = !{!"bux", !"baz"}

``````````

</details>


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


More information about the llvm-commits mailing list