https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/134838
Fixes #134480 >From e945a79a89839db98c4d43c1825b07cb1bda4a98 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <matthew.arsena...@amd.com> Date: Tue, 8 Apr 2025 17:31:24 +0700 Subject: [PATCH] Attributor: Propagate align to cmpxchg instructions Fixes #134480 --- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 9 +++++++++ llvm/test/Transforms/Attributor/align-atomic.ll | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 717ba7f688548..cc6e846f4f211 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -5317,6 +5317,15 @@ struct AAAlignImpl : AAAlign { InstrChanged = ChangeStatus::CHANGED; } } + } else if (auto *CAS = dyn_cast<AtomicCmpXchgInst>(U.getUser())) { + if (CAS->getPointerOperand() == &AssociatedValue) { + if (CAS->getAlign() < getAssumedAlign()) { + STATS_DECLTRACK(AAAlign, AtomicCmpXchg, + "Number of times alignment added to cmpxchg"); + CAS->setAlignment(getAssumedAlign()); + InstrChanged = ChangeStatus::CHANGED; + } + } } } diff --git a/llvm/test/Transforms/Attributor/align-atomic.ll b/llvm/test/Transforms/Attributor/align-atomic.ll index 0931c14685a87..0b363741cc168 100644 --- a/llvm/test/Transforms/Attributor/align-atomic.ll +++ b/llvm/test/Transforms/Attributor/align-atomic.ll @@ -37,7 +37,7 @@ define ptr @atomicrmw_non_ptr_op_no_propagate(ptr %ptr, ptr align 16 %val) { define i32 @cmpxchg_propagate(ptr align 8 %ptr, i32 %cmp, i32 %val) { ; CHECK-LABEL: define i32 @cmpxchg_propagate( ; CHECK-SAME: ptr nofree noundef nonnull align 8 captures(none) dereferenceable(4) [[PTR:%.*]], i32 [[CMP:%.*]], i32 [[VAL:%.*]]) #[[ATTR0]] { -; CHECK-NEXT: [[PAIR:%.*]] = cmpxchg ptr [[PTR]], i32 [[CMP]], i32 [[VAL]] seq_cst monotonic, align 2 +; CHECK-NEXT: [[PAIR:%.*]] = cmpxchg ptr [[PTR]], i32 [[CMP]], i32 [[VAL]] seq_cst monotonic, align 8 ; CHECK-NEXT: [[RESULT:%.*]] = extractvalue { i32, i1 } [[PAIR]], 0 ; CHECK-NEXT: ret i32 [[RESULT]] ; _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits