llvm.org GIT mirror llvm / 920653d
Teach alias analysis about readnone/readonly functions. Based on a patch by Török Edwin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44279 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 12 years ago
2 changed file(s) with 39 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
951951 if (Ptr != OnlyReadsMemoryTable->end() && strcmp(*Ptr, NamePtr) == 0)
952952 return OnlyReadsMemory;
953953
954 const ParamAttrsList *Attrs = F->getFunctionType()->getParamAttrs();
955 if (Attrs && Attrs->paramHasAttr(0, ParamAttr::ReadNone))
956 return DoesNotAccessMemory;
957 if (Attrs && Attrs->paramHasAttr(0, ParamAttr::ReadOnly))
958 return OnlyReadsMemory;
959
954960 return UnknownModRefBehavior;
955961 }
956962
0 ; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestConst | count 2
1 ; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestPure | not count 2
2 ; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestNone | count 4
3 @g = global i32 0 ; [#uses=1]
4
5 define i32 @test() {
6 entry:
7 %tmp0 = call i32 @TestConst( i32 5 ) readnone ; [#uses=1]
8 %tmp1 = call i32 @TestPure( i32 6 ) readonly ; [#uses=1]
9 %tmp2 = call i32 @TestNone( i32 7 ) ; [#uses=1]
10 store i32 1, i32* @g
11 %tmp3 = call i32 @TestConst( i32 5 ) readnone ; [#uses=1]
12 %tmp4 = call i32 @TestConst( i32 5 ) readnone ; [#uses=1]
13 %tmp5 = call i32 @TestPure( i32 6 ) readonly ; [#uses=1]
14 %tmp6 = call i32 @TestPure( i32 6 ) readonly ; [#uses=1]
15 %tmp7 = call i32 @TestNone( i32 7 ) ; [#uses=1]
16 %tmp8 = call i32 @TestNone( i32 7 ) ; [#uses=1]
17 %sum0 = add i32 %tmp0, %tmp1 ; [#uses=1]
18 %sum1 = add i32 %sum0, %tmp2 ; [#uses=1]
19 %sum2 = add i32 %sum1, %tmp3 ; [#uses=1]
20 %sum3 = add i32 %sum2, %tmp4 ; [#uses=1]
21 %sum4 = add i32 %sum3, %tmp5 ; [#uses=1]
22 %sum5 = add i32 %sum4, %tmp6 ; [#uses=1]
23 %sum6 = add i32 %sum5, %tmp7 ; [#uses=1]
24 %sum7 = add i32 %sum6, %tmp8 ; [#uses=1]
25 ret i32 %sum7
26 }
27
28 declare i32 @TestConst(i32) readnone
29
30 declare i32 @TestPure(i32) readonly
31
32 declare i32 @TestNone(i32)