Skip to content

Commit 04d450f

Browse files
authored
AtomicExpand: Preserve metadata when bitcasting fp atomicrmw xchg (#115240)
1 parent fa20b5d commit 04d450f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

llvm/lib/CodeGen/AtomicExpandPass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ AtomicExpandImpl::convertAtomicXchgToIntegerType(AtomicRMWInst *RMWI) {
496496
RMWI->getAlign(), RMWI->getOrdering(),
497497
RMWI->getSyncScopeID());
498498
NewRMWI->setVolatile(RMWI->isVolatile());
499+
copyMetadataForAtomic(*NewRMWI, *RMWI);
499500
LLVM_DEBUG(dbgs() << "Replaced " << *RMWI << " with " << *NewRMWI << "\n");
500501

501502
Value *NewRVal = RMWI->getType()->isPointerTy()

llvm/test/Transforms/AtomicExpand/X86/expand-atomic-xchg-fp.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,25 @@ define double @atomic_xchg_f64_as1(ptr addrspace(1) %ptr) nounwind {
3636
%result = atomicrmw xchg ptr addrspace(1) %ptr, double 4.0 seq_cst
3737
ret double %result
3838
}
39+
40+
define double @atomic_xchg_f64_preserve_md(ptr %ptr) nounwind {
41+
; CHECK-LABEL: @atomic_xchg_f64_preserve_md(
42+
; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[PTR:%.*]], align 8, !mmra [[META0:![0-9]+]]
43+
; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]]
44+
; CHECK: atomicrmw.start:
45+
; CHECK-NEXT: [[LOADED:%.*]] = phi i64 [ [[TMP1]], [[TMP0:%.*]] ], [ [[NEWLOADED:%.*]], [[ATOMICRMW_START]] ]
46+
; CHECK-NEXT: [[TMP2:%.*]] = cmpxchg ptr [[PTR]], i64 [[LOADED]], i64 4616189618054758400 seq_cst seq_cst, align 8, !mmra [[META0]]
47+
; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP2]], 1
48+
; CHECK-NEXT: [[NEWLOADED]] = extractvalue { i64, i1 } [[TMP2]], 0
49+
; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
50+
; CHECK: atomicrmw.end:
51+
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i64 [[NEWLOADED]] to double
52+
; CHECK-NEXT: ret double [[TMP3]]
53+
;
54+
%result = atomicrmw xchg ptr %ptr, double 4.000000e+00 seq_cst, align 8, !mmra !0
55+
ret double %result
56+
}
57+
58+
!0 = !{!1, !2}
59+
!1 = !{!"foo", !"bar"}
60+
!2 = !{!"bux", !"baz"}

0 commit comments

Comments
 (0)