1 ; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NOLIMIT
2 ; RUN: opt -memssa-check-limit=0 -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,LIMIT
3 ; RUN: opt -aa-pipeline=basic-aa -passes='print<memoryssa>,verify<memoryssa>' -disable-output < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NOLIMIT
4 ; RUN: opt -memssa-check-limit=0 -aa-pipeline=basic-aa -passes='print<memoryssa>,verify<memoryssa>' -disable-output < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,LIMIT
6 ; %ptr can't alias %local, so we should be able to optimize the use of %local to
7 ; point to the store to %local.
8 ; CHECK-LABEL: define void @check
9 define void @check(i8* %ptr, i1 %bool) {
11 %local = alloca i8, align 1
12 ; CHECK: 1 = MemoryDef(liveOnEntry)
13 ; CHECK-NEXT: store i8 0, i8* %local, align 1
14 store i8 0, i8* %local, align 1
15 br i1 %bool, label %if.then, label %if.end
18 %p2 = getelementptr inbounds i8, i8* %ptr, i32 1
19 ; CHECK: 2 = MemoryDef(1)
20 ; CHECK-NEXT: store i8 0, i8* %p2, align 1
21 store i8 0, i8* %p2, align 1
25 ; CHECK: 3 = MemoryPhi({entry,1},{if.then,2})
26 ; NOLIMIT: MemoryUse(1) MayAlias
27 ; NOLIMIT-NEXT: load i8, i8* %local, align 1
28 ; LIMIT: MemoryUse(3) MayAlias
29 ; LIMIT-NEXT: load i8, i8* %local, align 1
30 load i8, i8* %local, align 1
34 ; CHECK-LABEL: define void @check2
35 define void @check2(i1 %val1, i1 %val2, i1 %val3) {
37 %local = alloca i8, align 1
38 %local2 = alloca i8, align 1
40 ; CHECK: 1 = MemoryDef(liveOnEntry)
41 ; CHECK-NEXT: store i8 0, i8* %local
42 store i8 0, i8* %local
43 br i1 %val1, label %if.then, label %phi.3
46 ; CHECK: 2 = MemoryDef(1)
47 ; CHECK-NEXT: store i8 2, i8* %local2
48 store i8 2, i8* %local2
49 br i1 %val2, label %phi.2, label %phi.3
52 ; CHECK: 7 = MemoryPhi({entry,1},{if.then,2})
53 ; CHECK: 3 = MemoryDef(7)
54 ; CHECK-NEXT: store i8 3, i8* %local2
55 store i8 3, i8* %local2
56 br i1 %val3, label %phi.2, label %phi.1
59 ; CHECK: 5 = MemoryPhi({if.then,2},{phi.3,3})
60 ; CHECK: 4 = MemoryDef(5)
61 ; CHECK-NEXT: store i8 4, i8* %local2
62 store i8 4, i8* %local2
66 ; Order matters here; phi.2 needs to come before phi.3, because that's the order
68 ; CHECK: 6 = MemoryPhi({phi.2,4},{phi.3,3})
69 ; NOLIMIT: MemoryUse(1) MayAlias
70 ; NOLIMIT-NEXT: load i8, i8* %local
71 ; LIMIT: MemoryUse(6) MayAlias
72 ; LIMIT-NEXT: load i8, i8* %local
77 ; CHECK-LABEL: define void @cross_phi
78 define void @cross_phi(i8* noalias %p1, i8* noalias %p2) {
79 ; CHECK: 1 = MemoryDef(liveOnEntry)
80 ; CHECK-NEXT: store i8 0, i8* %p1
82 ; NOLIMIT: MemoryUse(1) MustAlias
83 ; NOLIMIT-NEXT: load i8, i8* %p1
84 ; LIMIT: MemoryUse(1) MayAlias
85 ; LIMIT-NEXT: load i8, i8* %p1
87 br i1 undef, label %a, label %b
90 ; CHECK: 2 = MemoryDef(1)
91 ; CHECK-NEXT: store i8 0, i8* %p2
93 br i1 undef, label %c, label %d
96 ; CHECK: 3 = MemoryDef(1)
97 ; CHECK-NEXT: store i8 1, i8* %p2
99 br i1 undef, label %c, label %d
102 ; CHECK: 6 = MemoryPhi({a,2},{b,3})
103 ; CHECK: 4 = MemoryDef(6)
104 ; CHECK-NEXT: store i8 2, i8* %p2
109 ; CHECK: 7 = MemoryPhi({a,2},{b,3})
110 ; CHECK: 5 = MemoryDef(7)
111 ; CHECK-NEXT: store i8 3, i8* %p2
116 ; 8 = MemoryPhi({c,4},{d,5})
117 ; NOLIMIT: MemoryUse(1) MustAlias
118 ; NOLIMIT-NEXT: load i8, i8* %p1
119 ; LIMIT: MemoryUse(8) MayAlias
120 ; LIMIT-NEXT: load i8, i8* %p1
125 ; CHECK-LABEL: define void @looped
126 define void @looped(i8* noalias %p1, i8* noalias %p2) {
127 ; CHECK: 1 = MemoryDef(liveOnEntry)
128 ; CHECK-NEXT: store i8 0, i8* %p1
133 ; CHECK: 6 = MemoryPhi({%0,1},{loop.3,4})
134 ; CHECK: 2 = MemoryDef(6)
135 ; CHECK-NEXT: store i8 0, i8* %p2
137 br i1 undef, label %loop.2, label %loop.3
140 ; CHECK: 5 = MemoryPhi({loop.1,2},{loop.3,4})
141 ; CHECK: 3 = MemoryDef(5)
142 ; CHECK-NEXT: store i8 1, i8* %p2
147 ; CHECK: 7 = MemoryPhi({loop.1,2},{loop.2,3})
148 ; CHECK: 4 = MemoryDef(7)
149 ; CHECK-NEXT: store i8 2, i8* %p2
151 ; NOLIMIT: MemoryUse(1) MayAlias
152 ; NOLIMIT-NEXT: load i8, i8* %p1
153 ; LIMIT: MemoryUse(4) MayAlias
154 ; LIMIT-NEXT: load i8, i8* %p1
156 br i1 undef, label %loop.2, label %loop.1
159 ; CHECK-LABEL: define void @looped_visitedonlyonce
160 define void @looped_visitedonlyonce(i8* noalias %p1, i8* noalias %p2) {
164 ; CHECK: 5 = MemoryPhi({%0,liveOnEntry},{if.end,3})
165 ; CHECK-NEXT: br i1 undef, label %if.then, label %if.end
166 br i1 undef, label %if.then, label %if.end
169 ; CHECK: 1 = MemoryDef(5)
170 ; CHECK-NEXT: store i8 0, i8* %p1
172 br i1 undef, label %if.end, label %if.then2
175 ; CHECK: 2 = MemoryDef(1)
176 ; CHECK-NEXT: store i8 1, i8* %p2
181 ; CHECK: 4 = MemoryPhi({while.cond,5},{if.then,1},{if.then2,2})
182 ; CHECK: MemoryUse(4) MayAlias
183 ; CHECK-NEXT: load i8, i8* %p1
185 ; CHECK: 3 = MemoryDef(4)
186 ; CHECK-NEXT: store i8 2, i8* %p2
188 ; NOLIMIT: MemoryUse(4) MayAlias
189 ; NOLIMIT-NEXT: load i8, i8* %p1
190 ; LIMIT: MemoryUse(3) MayAlias
191 ; LIMIT-NEXT: load i8, i8* %p1