modref.ll
7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -basic-aa -gvn -dse -S | FileCheck %s
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
declare void @external(i32*)
define i32 @test0(i8* %P) {
; CHECK-LABEL: @test0(
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
; CHECK-NEXT: call void @external(i32* [[A]])
; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* [[P:%.*]], i8 0, i32 42, i1 false)
; CHECK-NEXT: ret i32 0
;
%A = alloca i32
call void @external(i32* %A)
store i32 0, i32* %A
call void @llvm.memset.p0i8.i32(i8* %P, i8 0, i32 42, i1 false)
%B = load i32, i32* %A
ret i32 %B
}
define i8 @test1() {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret i8 2
;
%A = alloca i8
%B = alloca i8
store i8 2, i8* %B ;; Not written to by memcpy
call void @llvm.memcpy.p0i8.p0i8.i8(i8* %A, i8* %B, i8 -1, i1 false)
%C = load i8, i8* %B
ret i8 %C
}
define i8 @test2(i8* %P) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: [[P2:%.*]] = getelementptr i8, i8* [[P:%.*]], i32 127
; CHECK-NEXT: store i8 1, i8* [[P2]], align 1
; CHECK-NEXT: call void @llvm.memset.p0i8.i8(i8* [[P]], i8 2, i8 127, i1 false)
; CHECK-NEXT: ret i8 1
;
%P2 = getelementptr i8, i8* %P, i32 127
store i8 1, i8* %P2 ;; Not dead across memset
call void @llvm.memset.p0i8.i8(i8* %P, i8 2, i8 127, i1 false)
%A = load i8, i8* %P2
ret i8 %A
}
define i8 @test2a(i8* %P) {
; CHECK-LABEL: @test2a(
; CHECK-NEXT: call void @llvm.memset.p0i8.i8(i8* [[P:%.*]], i8 2, i8 127, i1 false)
; CHECK-NEXT: ret i8 2
;
%P2 = getelementptr i8, i8* %P, i32 126
store i8 1, i8* %P2 ;; Dead, clobbered by memset.
call void @llvm.memset.p0i8.i8(i8* %P, i8 2, i8 127, i1 false)
%A = load i8, i8* %P2
ret i8 %A
}
define void @test3(i8* %P, i8 %X) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: [[P2:%.*]] = getelementptr i8, i8* [[P:%.*]], i32 2
; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* [[P]])
; CHECK-NEXT: store i8 2, i8* [[P2]], align 1
; CHECK-NEXT: ret void
;
%Y = add i8 %X, 1 ;; Dead, because the only use (the store) is dead.
%P2 = getelementptr i8, i8* %P, i32 2
store i8 %Y, i8* %P2 ;; Not read by lifetime.end, should be removed.
call void @llvm.lifetime.end.p0i8(i64 1, i8* %P)
store i8 2, i8* %P2
ret void
}
define void @test3a(i8* %P, i8 %X) {
; CHECK-LABEL: @test3a(
; CHECK-NEXT: ret void
;
%Y = add i8 %X, 1 ;; Dead, because the only use (the store) is dead.
%P2 = getelementptr i8, i8* %P, i32 2
store i8 %Y, i8* %P2
call void @llvm.lifetime.end.p0i8(i64 10, i8* %P)
ret void
}
@G1 = external global i32
@G2 = external global [4000 x i32]
define i32 @test4(i8* %P) {
; CHECK-LABEL: @test4(
; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* bitcast ([4000 x i32]* @G2 to i8*), i8 0, i32 4000, i1 false)
; CHECK-NEXT: ret i32 0
;
%tmp = load i32, i32* @G1
call void @llvm.memset.p0i8.i32(i8* bitcast ([4000 x i32]* @G2 to i8*), i8 0, i32 4000, i1 false)
%tmp2 = load i32, i32* @G1
%sub = sub i32 %tmp2, %tmp
ret i32 %sub
}
; Verify that basicaa is handling variable length memcpy, knowing it doesn't
; write to G1.
define i32 @test5(i8* %P, i32 %Len) {
; CHECK-LABEL: @test5(
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast ([4000 x i32]* @G2 to i8*), i8* bitcast (i32* @G1 to i8*), i32 [[LEN:%.*]], i1 false)
; CHECK-NEXT: ret i32 0
;
%tmp = load i32, i32* @G1
call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast ([4000 x i32]* @G2 to i8*), i8* bitcast (i32* @G1 to i8*), i32 %Len, i1 false)
%tmp2 = load i32, i32* @G1
%sub = sub i32 %tmp2, %tmp
ret i32 %sub
}
define i8 @test6(i8* %p, i8* noalias %a) {
; CHECK-LABEL: @test6(
; CHECK-NEXT: [[X:%.*]] = load i8, i8* [[A:%.*]], align 1
; CHECK-NEXT: [[T:%.*]] = va_arg i8* [[P:%.*]], float
; CHECK-NEXT: [[Z:%.*]] = add i8 [[X]], [[X]]
; CHECK-NEXT: ret i8 [[Z]]
;
%x = load i8, i8* %a
%t = va_arg i8* %p, float
%y = load i8, i8* %a
%z = add i8 %x, %y
ret i8 %z
}
; PR10628
declare void @test7decl(i32* nocapture %x)
define i32 @test7() nounwind uwtable ssp {
; CHECK-LABEL: @test7(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[X:%.*]] = alloca i32, align 4
; CHECK-NEXT: store i32 0, i32* [[X]], align 4
; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, i32* [[X]], i64 1
; CHECK-NEXT: call void @test7decl(i32* [[ADD_PTR]])
; CHECK-NEXT: [[TMP:%.*]] = load i32, i32* [[X]], align 4
; CHECK-NEXT: ret i32 [[TMP]]
;
entry:
%x = alloca i32, align 4
store i32 0, i32* %x, align 4
%add.ptr = getelementptr inbounds i32, i32* %x, i64 1
call void @test7decl(i32* %add.ptr)
%tmp = load i32, i32* %x, align 4
ret i32 %tmp
}
;; Check that aa correctly handles functions marked with argmemonly
;; attribute.
declare i32 @func_argmemonly(i32 * %P) argmemonly
;; Can not remove redundant load, function may write to it.
define i32 @test8(i32 *%P) {
; CHECK-LABEL: @test8(
; CHECK-NEXT: [[V1:%.*]] = load i32, i32* [[P:%.*]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(i32* [[P]])
; CHECK-NEXT: [[V2:%.*]] = load i32, i32* [[P]], align 4
; CHECK-NEXT: [[DIFF:%.*]] = sub i32 [[V1]], [[V2]]
; CHECK-NEXT: ret i32 [[DIFF]]
;
%V1 = load i32, i32* %P
call i32 @func_argmemonly(i32* %P)
%V2 = load i32, i32* %P
%Diff = sub i32 %V1, %V2
ret i32 %Diff
}
;; In this case load can be removed, function clobbers only %P2.
define i32 @test9(i32* %P, i32* noalias %P2) {
; CHECK-LABEL: @test9(
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(i32* [[P2:%.*]])
; CHECK-NEXT: ret i32 0
;
%V1 = load i32, i32* %P
call i32 @func_argmemonly(i32* %P2)
%V2 = load i32, i32* %P
%Diff = sub i32 %V1, %V2
ret i32 %Diff
}
;; In this case load can *not* be removed. Function clobers only %P2 but it may
;; alias with %P.
define i32 @test10(i32* %P, i32* %P2) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: [[V1:%.*]] = load i32, i32* [[P:%.*]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(i32* [[P2:%.*]])
; CHECK-NEXT: [[V2:%.*]] = load i32, i32* [[P]], align 4
; CHECK-NEXT: [[DIFF:%.*]] = sub i32 [[V1]], [[V2]]
; CHECK-NEXT: ret i32 [[DIFF]]
;
%V1 = load i32, i32* %P
call i32 @func_argmemonly(i32* %P2)
%V2 = load i32, i32* %P
%Diff = sub i32 %V1, %V2
ret i32 %Diff
}
define i32 @test11(i32* %P, i32* %P2) {
; CHECK-LABEL: @test11(
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(i32* readonly [[P2:%.*]])
; CHECK-NEXT: ret i32 0
;
%V1 = load i32, i32* %P
call i32 @func_argmemonly(i32* readonly %P2)
%V2 = load i32, i32* %P
%Diff = sub i32 %V1, %V2
ret i32 %Diff
}
declare i32 @func_argmemonly_two_args(i32* %P, i32* %P2) argmemonly
define i32 @test12(i32* %P, i32* %P2, i32* %P3) {
; CHECK-LABEL: @test12(
; CHECK-NEXT: [[V1:%.*]] = load i32, i32* [[P:%.*]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly_two_args(i32* readonly [[P2:%.*]], i32* [[P3:%.*]])
; CHECK-NEXT: [[V2:%.*]] = load i32, i32* [[P]], align 4
; CHECK-NEXT: [[DIFF:%.*]] = sub i32 [[V1]], [[V2]]
; CHECK-NEXT: ret i32 [[DIFF]]
;
%V1 = load i32, i32* %P
call i32 @func_argmemonly_two_args(i32* readonly %P2, i32* %P3)
%V2 = load i32, i32* %P
%Diff = sub i32 %V1, %V2
ret i32 %Diff
}
define i32 @test13(i32* %P, i32* %P2) {
; CHECK-LABEL: @test13(
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @func_argmemonly(i32* readnone [[P2:%.*]])
; CHECK-NEXT: ret i32 0
;
%V1 = load i32, i32* %P
call i32 @func_argmemonly(i32* readnone %P2)
%V2 = load i32, i32* %P
%Diff = sub i32 %V1, %V2
ret i32 %Diff
}
declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1) nounwind
declare void @llvm.memset.p0i8.i8(i8* nocapture, i8, i8, i1) nounwind
declare void @llvm.memcpy.p0i8.p0i8.i8(i8* nocapture, i8* nocapture, i8, i1) nounwind
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind