Skip to content

Commit

Permalink
[Attributor] Propagate known align from arguments to call sites argum…
Browse files Browse the repository at this point in the history
…ents

Since the information is known we can simply use it at the call site.
This is especially useful for callbacks but also helps regular calls.

The test changes are mechanical.
  • Loading branch information
jdoerfert committed Dec 31, 2019
1 parent b1b441d commit dada813
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
12 changes: 12 additions & 0 deletions llvm/lib/Transforms/IPO/Attributor.cpp
Expand Up @@ -3666,6 +3666,18 @@ struct AAAlignCallSiteArgument final : AAAlignFloating {
return AAAlignImpl::manifest(A);
}

/// See AbstractAttribute::updateImpl(Attributor &A).
ChangeStatus updateImpl(Attributor &A) override {
ChangeStatus Changed = AAAlignFloating::updateImpl(A);
if (Argument *Arg = getAssociatedArgument()) {
const auto &ArgAlignAA = A.getAAFor<AAAlign>(
*this, IRPosition::argument(*Arg), /* TrackDependence */ false,
DepClassTy::OPTIONAL);
takeKnownMaximum(ArgAlignAA.getKnownAlign());
}
return Changed;
}

/// See AbstractAttribute::trackStatistics()
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(aligned) }
};
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/Attributor/ArgumentPromotion/dbg.ll
Expand Up @@ -30,7 +30,7 @@ define internal void @test_byval(%struct.pair* byval %P) {
define void @caller(i32** %Y, %struct.pair* %P) {
; CHECK-LABEL: define {{[^@]+}}@caller
; CHECK-SAME: (i32** nocapture readonly [[Y:%.*]], %struct.pair* nocapture nofree readonly [[P:%.*]])
; CHECK-NEXT: call void @test(i32** nocapture readonly [[Y]]), !dbg !4
; CHECK-NEXT: call void @test(i32** nocapture readonly align 8 [[Y]]), !dbg !4
; CHECK-NEXT: call void @test_byval(%struct.pair* nocapture nofree readonly undef), !dbg !5
; CHECK-NEXT: ret void
;
Expand Down
Expand Up @@ -10,7 +10,7 @@ define i32 @fn2() local_unnamed_addr {
; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* @b, align 4
; CHECK-NEXT: [[TMP2:%.*]] = sext i32 [[TMP1]] to i64
; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to i32*
; CHECK-NEXT: call fastcc void @fn1(i32* nofree readonly [[TMP3]])
; CHECK-NEXT: call fastcc void @fn1(i32* nofree readonly align 4 [[TMP3]])
; CHECK-NEXT: ret i32 undef
;
%1 = load i32, i32* @b, align 4
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/Attributor/callbacks.ll
Expand Up @@ -13,7 +13,6 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
; each other but argument 3-5 of the transitive call site in the caller match
; arguments 2-4 of the callback callee. Here we should see information and value
; transfer in both directions.
; FIXME: %a should be align 256 at the call site

define void @t0_caller(i32* %a) {
; CHECK-LABEL: @t0_caller(
Expand All @@ -24,7 +23,7 @@ define void @t0_caller(i32* %a) {
; CHECK-NEXT: [[TMP0:%.*]] = bitcast i32* [[B]] to i8*
; CHECK-NEXT: store i32 42, i32* [[B]], align 32
; CHECK-NEXT: store i32* [[B]], i32** [[C]], align 64
; CHECK-NEXT: call void (i32*, i32*, void (i32*, i32*, ...)*, ...) @t0_callback_broker(i32* noalias null, i32* nonnull align 128 dereferenceable(4) [[PTR]], void (i32*, i32*, ...)* nonnull bitcast (void (i32*, i32*, i32*, i64, i32**)* @t0_callback_callee to void (i32*, i32*, ...)*), i32* [[A:%.*]], i64 99, i32** noalias nocapture nonnull readonly align 64 dereferenceable(8) [[C]])
; CHECK-NEXT: call void (i32*, i32*, void (i32*, i32*, ...)*, ...) @t0_callback_broker(i32* noalias null, i32* nonnull align 128 dereferenceable(4) [[PTR]], void (i32*, i32*, ...)* nonnull bitcast (void (i32*, i32*, i32*, i64, i32**)* @t0_callback_callee to void (i32*, i32*, ...)*), i32* align 256 [[A:%.*]], i64 99, i32** noalias nocapture nonnull readonly align 64 dereferenceable(8) [[C]])

; CHECK-NEXT: ret void
;
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/Transforms/Attributor/nocapture-2.ll
Expand Up @@ -275,7 +275,7 @@ entry:
; not_captured_but_returned_1(a);
; }
;
; CHECK: define void @test_not_captured_but_returned_calls(i64* nocapture nofree writeonly %a)
; CHECK: define void @test_not_captured_but_returned_calls(i64* nocapture nofree writeonly align 8 %a)
define void @test_not_captured_but_returned_calls(i64* %a) #0 {
entry:
%call = call i64* @not_captured_but_returned_0(i64* %a)
Expand All @@ -290,7 +290,7 @@ entry:
; }
;
; There should *not* be a no-capture attribute on %a
; CHECK: define i64* @negative_test_not_captured_but_returned_call_0a(i64* nofree returned writeonly "no-capture-maybe-returned" %a)
; CHECK: define align 8 i64* @negative_test_not_captured_but_returned_call_0a(i64* nofree returned writeonly align 8 "no-capture-maybe-returned" %a)
define i64* @negative_test_not_captured_but_returned_call_0a(i64* %a) #0 {
entry:
%call = call i64* @not_captured_but_returned_0(i64* %a)
Expand All @@ -304,7 +304,7 @@ entry:
; }
;
; There should *not* be a no-capture attribute on %a
; CHECK: define void @negative_test_not_captured_but_returned_call_0b(i64* nofree writeonly %a)
; CHECK: define void @negative_test_not_captured_but_returned_call_0b(i64* nofree writeonly align 8 %a)
define void @negative_test_not_captured_but_returned_call_0b(i64* %a) #0 {
entry:
%call = call i64* @not_captured_but_returned_0(i64* %a)
Expand All @@ -320,7 +320,7 @@ entry:
; }
;
; There should *not* be a no-capture attribute on %a
; CHECK: define nonnull align 8 dereferenceable(8) i64* @negative_test_not_captured_but_returned_call_1a(i64* nofree writeonly "no-capture-maybe-returned" %a)
; CHECK: define nonnull align 8 dereferenceable(8) i64* @negative_test_not_captured_but_returned_call_1a(i64* nofree writeonly align 8 "no-capture-maybe-returned" %a)
define i64* @negative_test_not_captured_but_returned_call_1a(i64* %a) #0 {
entry:
%call = call i64* @not_captured_but_returned_1(i64* %a)
Expand All @@ -334,7 +334,7 @@ entry:
; }
;
; There should *not* be a no-capture attribute on %a
; CHECK: define void @negative_test_not_captured_but_returned_call_1b(i64* nofree writeonly %a)
; CHECK: define void @negative_test_not_captured_but_returned_call_1b(i64* nofree writeonly align 8 %a)
define void @negative_test_not_captured_but_returned_call_1b(i64* %a) #0 {
entry:
%call = call i64* @not_captured_but_returned_1(i64* %a)
Expand Down

0 comments on commit dada813

Please sign in to comment.