Skip to content

Commit cbab334

Browse files
committedAug 29, 2019
[Attributor] Deduce "noalias" attribute
Summary: This patch adds very basic deduction for noalias. Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Tags: LLVM Differential Revision: https://reviews.llvm.org/D66207 llvm-svn: 370295
1 parent 1ec5c20 commit cbab334

File tree

3 files changed

+109
-8
lines changed

3 files changed

+109
-8
lines changed
 

Diff for: ‎llvm/lib/Transforms/IPO/Attributor.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,12 @@ struct AANoAliasImpl : AANoAlias {
15591559
struct AANoAliasFloating final : AANoAliasImpl {
15601560
AANoAliasFloating(const IRPosition &IRP) : AANoAliasImpl(IRP) {}
15611561

1562+
/// See AbstractAttribute::initialize(...).
1563+
void initialize(Attributor &A) override {
1564+
// TODO: It isn't sound to initialize as the same with `AANoAliasImpl`
1565+
// because `noalias` may not be valid in the current position.
1566+
}
1567+
15621568
/// See AbstractAttribute::updateImpl(...).
15631569
ChangeStatus updateImpl(Attributor &A) override {
15641570
// TODO: Implement this.
@@ -1572,14 +1578,10 @@ struct AANoAliasFloating final : AANoAliasImpl {
15721578
};
15731579

15741580
/// NoAlias attribute for an argument.
1575-
struct AANoAliasArgument final : AANoAliasImpl {
1576-
AANoAliasArgument(const IRPosition &IRP) : AANoAliasImpl(IRP) {}
1577-
1578-
/// See AbstractAttribute::updateImpl(...).
1579-
ChangeStatus updateImpl(Attributor &A) override {
1580-
// TODO: Implement this.
1581-
return indicatePessimisticFixpoint();
1582-
}
1581+
struct AANoAliasArgument final
1582+
: AAArgumentFromCallSiteArguments<AANoAlias, AANoAliasImpl> {
1583+
AANoAliasArgument(const IRPosition &IRP)
1584+
: AAArgumentFromCallSiteArguments<AANoAlias, AANoAliasImpl>(IRP) {}
15831585

15841586
/// See AbstractAttribute::trackStatistics()
15851587
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(noalias) }
@@ -1588,6 +1590,12 @@ struct AANoAliasArgument final : AANoAliasImpl {
15881590
struct AANoAliasCallSiteArgument final : AANoAliasImpl {
15891591
AANoAliasCallSiteArgument(const IRPosition &IRP) : AANoAliasImpl(IRP) {}
15901592

1593+
/// See AbstractAttribute::initialize(...).
1594+
void initialize(Attributor &A) override {
1595+
// TODO: It isn't sound to initialize as the same with `AANoAliasImpl`
1596+
// because `noalias` may not be valid in the current position.
1597+
}
1598+
15911599
/// See AbstractAttribute::updateImpl(...).
15921600
ChangeStatus updateImpl(Attributor &A) override {
15931601
// TODO: Implement this.
@@ -2814,6 +2822,9 @@ void Attributor::identifyDefaultAbstractAttributes(
28142822
// Every argument with pointer type might be marked nonnull.
28152823
checkAndRegisterAA<AANonNullArgument>(ArgPos, *this, Whitelist);
28162824

2825+
// Every argument with pointer type might be marked noalias.
2826+
checkAndRegisterAA<AANoAliasArgument>(ArgPos, *this, Whitelist);
2827+
28172828
// Every argument with pointer type might be marked dereferenceable.
28182829
checkAndRegisterAA<AADereferenceableArgument>(ArgPos, *this, Whitelist);
28192830

@@ -2879,6 +2890,10 @@ void Attributor::identifyDefaultAbstractAttributes(
28792890
checkAndRegisterAA<AANonNullCallSiteArgument>(CSArgPos, *this,
28802891
Whitelist);
28812892

2893+
// Call site argument attribute "no-alias".
2894+
checkAndRegisterAA<AANoAliasCallSiteArgument>(CSArgPos, *this,
2895+
Whitelist);
2896+
28822897
// Call site argument attribute "dereferenceable".
28832898
checkAndRegisterAA<AADereferenceableCallSiteArgument>(CSArgPos, *this,
28842899
Whitelist);
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; RUN: opt -S -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=9 < %s | FileCheck %s
2+
3+
define dso_local i32 @visible(i32* noalias %A, i32* noalias %B) #0 {
4+
entry:
5+
%call1 = call i32 @noalias_args(i32* %A, i32* %B)
6+
%call2 = call i32 @noalias_args_argmem(i32* %A, i32* %B)
7+
%add = add nsw i32 %call1, %call2
8+
ret i32 %add
9+
}
10+
11+
; FIXME: Should be something like this.
12+
; define internal i32 @noalias_args(i32* nocapture readonly %A, i32* noalias nocapture readonly %B)
13+
; CHECK: define internal i32 @noalias_args(i32* %A, i32* %B)
14+
15+
define internal i32 @noalias_args(i32* %A, i32* %B) #0 {
16+
entry:
17+
%0 = load i32, i32* %A, align 4
18+
%1 = load i32, i32* %B, align 4
19+
%add = add nsw i32 %0, %1
20+
%call = call i32 @noalias_args_argmem(i32* %A, i32* %B)
21+
%add2 = add nsw i32 %add, %call
22+
ret i32 %add2
23+
}
24+
25+
26+
; FIXME: Should be something like this.
27+
; define internal i32 @noalias_args_argmem(i32* noalias nocapture readonly %A, i32* noalias nocapture readonly %B)
28+
; CHECK: define internal i32 @noalias_args_argmem(i32* %A, i32* %B)
29+
;
30+
define internal i32 @noalias_args_argmem(i32* %A, i32* %B) #1 {
31+
entry:
32+
%0 = load i32, i32* %A, align 4
33+
%1 = load i32, i32* %B, align 4
34+
%add = add nsw i32 %0, %1
35+
ret i32 %add
36+
}
37+
38+
define dso_local i32 @visible_local(i32* %A) #0 {
39+
entry:
40+
%B = alloca i32, align 4
41+
store i32 5, i32* %B, align 4
42+
%call1 = call i32 @noalias_args(i32* %A, i32* nonnull %B)
43+
%call2 = call i32 @noalias_args_argmem(i32* %A, i32* nonnull %B)
44+
%add = add nsw i32 %call1, %call2
45+
ret i32 %add
46+
}
47+
48+
attributes #0 = { noinline nounwind uwtable willreturn }
49+
attributes #1 = { argmemonly noinline nounwind uwtable willreturn}

Diff for: ‎llvm/test/Transforms/FunctionAttrs/noalias_returned.ll

+37
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,40 @@ define i8* @test8(i32* %0) nounwind uwtable {
138138
5: ; preds = %1, %4
139139
ret i8* %2
140140
}
141+
142+
; TEST 9
143+
; Simple Argument Test
144+
define internal void @test9(i8* %a, i8* %b) {
145+
; FIXME: missing noalias
146+
; CHECK: define internal void @test9(i8* %a, i8* %b)
147+
ret void
148+
}
149+
define void @test9_helper(i8* %a, i8* %b) {
150+
tail call void @test9(i8* noalias %a, i8* %b)
151+
tail call void @test9(i8* noalias %b, i8* noalias %a)
152+
ret void
153+
}
154+
155+
156+
; TEST 10
157+
; Simple CallSite Test
158+
159+
declare void @test10_helper(i8* %a)
160+
define void @test10(i8* noalias %a) {
161+
; CHECK: define void @test10(i8* noalias %a)
162+
; FIXME: missing noalias
163+
; CHECK-NEXT: tail call void @test10_helper(i8* %a)
164+
tail call void @test10_helper(i8* %a)
165+
ret void
166+
}
167+
168+
; TEST 11
169+
; CallSite Test
170+
171+
declare void @test11_helper(i8* %a, i8 *%b)
172+
define void @test11(i8* noalias %a) {
173+
; CHECK: define void @test11(i8* noalias %a)
174+
; CHECK-NEXT: tail call void @test11_helper(i8* %a, i8* %a)
175+
tail call void @test11_helper(i8* %a, i8* %a)
176+
ret void
177+
}

0 commit comments

Comments
 (0)
Please sign in to comment.