Skip to content

Attributor: Propagate align to atomicrmw instructions #134837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5283,7 +5283,7 @@ struct AAAlignImpl : AAAlign {

/// See AbstractAttribute::manifest(...).
ChangeStatus manifest(Attributor &A) override {
ChangeStatus LoadStoreChanged = ChangeStatus::UNCHANGED;
ChangeStatus InstrChanged = ChangeStatus::UNCHANGED;

// Check for users that allow alignment annotations.
Value &AssociatedValue = getAssociatedValue();
Expand All @@ -5297,16 +5297,26 @@ struct AAAlignImpl : AAAlign {
STATS_DECLTRACK(AAAlign, Store,
"Number of times alignment added to a store");
SI->setAlignment(getAssumedAlign());
LoadStoreChanged = ChangeStatus::CHANGED;
InstrChanged = ChangeStatus::CHANGED;
}
} else if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {
if (LI->getPointerOperand() == &AssociatedValue)
if (LI->getAlign() < getAssumedAlign()) {
LI->setAlignment(getAssumedAlign());
STATS_DECLTRACK(AAAlign, Load,
"Number of times alignment added to a load");
LoadStoreChanged = ChangeStatus::CHANGED;
InstrChanged = ChangeStatus::CHANGED;
}
} else if (auto *RMW = dyn_cast<AtomicRMWInst>(U.getUser())) {
if (RMW->getPointerOperand() == &AssociatedValue) {
if (RMW->getAlign() < getAssumedAlign()) {
STATS_DECLTRACK(AAAlign, AtomicRMW,
"Number of times alignment added to atomicrmw");

RMW->setAlignment(getAssumedAlign());
InstrChanged = ChangeStatus::CHANGED;
}
}
}
}

Expand All @@ -5315,8 +5325,8 @@ struct AAAlignImpl : AAAlign {
Align InheritAlign =
getAssociatedValue().getPointerAlignment(A.getDataLayout());
if (InheritAlign >= getAssumedAlign())
return LoadStoreChanged;
return Changed | LoadStoreChanged;
return InstrChanged;
return Changed | InstrChanged;
}

// TODO: Provide a helper to determine the implied ABI alignment and check in
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/Attributor/align-atomic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ define i32 @atomicrmw_add_no_op(ptr align 4 %ptr, i32 %val) {
define i32 @atomicrmw_add_propagate(ptr align 8 %ptr, i32 %val) {
; CHECK-LABEL: define i32 @atomicrmw_add_propagate(
; CHECK-SAME: ptr nofree noundef nonnull align 8 captures(none) dereferenceable(4) [[PTR:%.*]], i32 [[VAL:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[RESULT:%.*]] = atomicrmw add ptr [[PTR]], i32 [[VAL]] seq_cst, align 2
; CHECK-NEXT: [[RESULT:%.*]] = atomicrmw add ptr [[PTR]], i32 [[VAL]] seq_cst, align 8
; CHECK-NEXT: ret i32 [[RESULT]]
;
%result = atomicrmw add ptr %ptr, i32 %val seq_cst, align 2
Expand Down
Loading