Skip to content

Commit

Permalink
[Attributor][FIX] Avoid setting wrong load/store alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
jdoerfert committed Feb 20, 2020
1 parent de6e968 commit a801ee8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/IPO/Attributor.cpp
Expand Up @@ -3796,18 +3796,18 @@ struct AAAlignImpl : AAAlign {
ChangeStatus LoadStoreChanged = ChangeStatus::UNCHANGED;

// Check for users that allow alignment annotations.
Value &AnchorVal = getIRPosition().getAnchorValue();
for (const Use &U : AnchorVal.uses()) {
Value &AssociatedValue = getAssociatedValue();
for (const Use &U : AssociatedValue.uses()) {
if (auto *SI = dyn_cast<StoreInst>(U.getUser())) {
if (SI->getPointerOperand() == &AnchorVal)
if (SI->getPointerOperand() == &AssociatedValue)
if (SI->getAlignment() < getAssumedAlign()) {
STATS_DECLTRACK(AAAlign, Store,
"Number of times alignment added to a store");
SI->setAlignment(Align(getAssumedAlign()));
LoadStoreChanged = ChangeStatus::CHANGED;
}
} else if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {
if (LI->getPointerOperand() == &AnchorVal)
if (LI->getPointerOperand() == &AssociatedValue)
if (LI->getAlignment() < getAssumedAlign()) {
LI->setAlignment(Align(getAssumedAlign()));
STATS_DECLTRACK(AAAlign, Load,
Expand Down
27 changes: 27 additions & 0 deletions llvm/test/Transforms/Attributor/align.ll
Expand Up @@ -527,6 +527,33 @@ define void @aligned_store(i8* %Value, i8** %Ptr) {
ret void
}

; UTC_ARGS: --enable
declare i8* @some_func(i8*)
define void @align_call_op_not_store(i8* align 2048 %arg) {
; ATTRIBUTOR-LABEL: define {{[^@]+}}@align_call_op_not_store
; ATTRIBUTOR-SAME: (i8* align 2048 [[ARG:%.*]])
; ATTRIBUTOR-NEXT: [[UNKNOWN:%.*]] = call i8* @some_func(i8* align 2048 [[ARG]])
; ATTRIBUTOR-NEXT: store i8 0, i8* [[UNKNOWN]]
; ATTRIBUTOR-NEXT: ret void
;
%unknown = call i8* @some_func(i8* %arg)
store i8 0, i8* %unknown
ret void
}
define void @align_store_after_bc(i32* align 2048 %arg) {
;
; ATTRIBUTOR-LABEL: define {{[^@]+}}@align_store_after_bc
; ATTRIBUTOR-SAME: (i32* nocapture nofree nonnull writeonly align 2048 dereferenceable(1) [[ARG:%.*]])
; ATTRIBUTOR-NEXT: [[BC:%.*]] = bitcast i32* [[ARG]] to i8*
; ATTRIBUTOR-NEXT: store i8 0, i8* [[BC]], align 2048
; ATTRIBUTOR-NEXT: ret void
;
%bc = bitcast i32* %arg to i8*
store i8 0, i8* %bc
ret void
}
; UTC_ARGS: --disable

attributes #0 = { nounwind uwtable noinline }
attributes #1 = { uwtable noinline }
attributes #2 = { "null-pointer-is-valid"="true" }
2 changes: 1 addition & 1 deletion llvm/test/Transforms/Attributor/returned.ll
Expand Up @@ -781,7 +781,7 @@ define i32 @exact(i32* %a) {
%c3 = call i32* @non_exact_3(i32* %a)
; We can use the information of the weak function non_exact_3 because it was
; given to us and not derived (the alignment of the returned argument).
; ATTRIBUTOR: %c4 = load i32, i32* %c3, align 32
; ATTRIBUTOR: %c4 = load i32, i32* %c3
%c4 = load i32, i32* %c3
; FIXME: %c2 and %c3 should be replaced but not %c0 or %c1!
; ATTRIBUTOR: %add1 = add i32 %c0, %c1
Expand Down

0 comments on commit a801ee8

Please sign in to comment.