Skip to content

Commit 4d6890e

Browse files
committed
Attributor: Propagate align to cmpxchg instructions
Fixes #134480
1 parent 66f0343 commit 4d6890e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5317,6 +5317,15 @@ struct AAAlignImpl : AAAlign {
53175317
InstrChanged = ChangeStatus::CHANGED;
53185318
}
53195319
}
5320+
} else if (auto *CAS = dyn_cast<AtomicCmpXchgInst>(U.getUser())) {
5321+
if (CAS->getPointerOperand() == &AssociatedValue) {
5322+
if (CAS->getAlign() < getAssumedAlign()) {
5323+
STATS_DECLTRACK(AAAlign, AtomicCmpXchg,
5324+
"Number of times alignment added to cmpxchg");
5325+
CAS->setAlignment(getAssumedAlign());
5326+
InstrChanged = ChangeStatus::CHANGED;
5327+
}
5328+
}
53205329
}
53215330
}
53225331

llvm/test/Transforms/Attributor/align-atomic.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ define ptr @atomicrmw_non_ptr_op_no_propagate(ptr %ptr, ptr align 16 %val) {
3737
define i32 @cmpxchg_propagate(ptr align 8 %ptr, i32 %cmp, i32 %val) {
3838
; CHECK-LABEL: define i32 @cmpxchg_propagate(
3939
; CHECK-SAME: ptr nofree noundef nonnull align 8 captures(none) dereferenceable(4) [[PTR:%.*]], i32 [[CMP:%.*]], i32 [[VAL:%.*]]) #[[ATTR0]] {
40-
; CHECK-NEXT: [[PAIR:%.*]] = cmpxchg ptr [[PTR]], i32 [[CMP]], i32 [[VAL]] seq_cst monotonic, align 2
40+
; CHECK-NEXT: [[PAIR:%.*]] = cmpxchg ptr [[PTR]], i32 [[CMP]], i32 [[VAL]] seq_cst monotonic, align 8
4141
; CHECK-NEXT: [[RESULT:%.*]] = extractvalue { i32, i1 } [[PAIR]], 0
4242
; CHECK-NEXT: ret i32 [[RESULT]]
4343
;

0 commit comments

Comments
 (0)