load.ll
11.4 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S < %s | FileCheck %s
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
target datalayout = "e-m:e-p:64:64:64-i64:64-f80:128-n8:16:32:64-S128"
@X = constant i32 42 ; <i32*> [#uses=2]
@X2 = constant i32 47 ; <i32*> [#uses=1]
@Y = constant [2 x { i32, float }] [ { i32, float } { i32 12, float 1.000000e+00 }, { i32, float } { i32 37, float 0x3FF3B2FEC0000000 } ] ; <[2 x { i32, float }]*> [#uses=2]
@Z = constant [2 x { i32, float }] zeroinitializer ; <[2 x { i32, float }]*> [#uses=1]
@GLOBAL = internal constant [4 x i32] zeroinitializer
define i32 @test1() {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret i32 42
;
%B = load i32, i32* @X ; <i32> [#uses=1]
ret i32 %B
}
define float @test2() {
; CHECK-LABEL: @test2(
; CHECK-NEXT: ret float 0x3FF3B2FEC0000000
;
%A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Y, i64 0, i64 1, i32 1 ; <float*> [#uses=1]
%B = load float, float* %A ; <float> [#uses=1]
ret float %B
}
define i32 @test3() {
; CHECK-LABEL: @test3(
; CHECK-NEXT: ret i32 12
;
%A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Y, i64 0, i64 0, i32 0 ; <i32*> [#uses=1]
%B = load i32, i32* %A ; <i32> [#uses=1]
ret i32 %B
}
define i32 @test4() {
; CHECK-LABEL: @test4(
; CHECK-NEXT: ret i32 0
;
%A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Z, i64 0, i64 1, i32 0 ; <i32*> [#uses=1]
%B = load i32, i32* %A ; <i32> [#uses=1]
ret i32 %B
}
define i32 @test5(i1 %C) {
; CHECK-LABEL: @test5(
; CHECK-NEXT: [[Z:%.*]] = select i1 [[C:%.*]], i32 42, i32 47
; CHECK-NEXT: ret i32 [[Z]]
;
%Y = select i1 %C, i32* @X, i32* @X2 ; <i32*> [#uses=1]
%Z = load i32, i32* %Y ; <i32> [#uses=1]
ret i32 %Z
}
define i32 @test7(i32 %X) {
; CHECK-LABEL: @test7(
; CHECK-NEXT: store i32 undef, i32* null, align 536870912
; CHECK-NEXT: ret i32 undef
;
%V = getelementptr i32, i32* null, i32 %X ; <i32*> [#uses=1]
%R = load i32, i32* %V ; <i32> [#uses=1]
ret i32 %R
}
define i32 @test7_no_null_opt(i32 %X) #0 {
; CHECK-LABEL: @test7_no_null_opt(
; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[X:%.*]] to i64
; CHECK-NEXT: [[V:%.*]] = getelementptr i32, i32* null, i64 [[TMP1]]
; CHECK-NEXT: [[R:%.*]] = load i32, i32* [[V]], align 4
; CHECK-NEXT: ret i32 [[R]]
;
%V = getelementptr i32, i32* null, i32 %X ; <i32*> [#uses=1]
%R = load i32, i32* %V ; <i32> [#uses=1]
ret i32 %R
}
attributes #0 = { "null-pointer-is-valid"="true" }
define i32 @test8(i32* %P) {
; CHECK-LABEL: @test8(
; CHECK-NEXT: store i32 1, i32* [[P:%.*]], align 4
; CHECK-NEXT: ret i32 1
;
store i32 1, i32* %P
%X = load i32, i32* %P ; <i32> [#uses=1]
ret i32 %X
}
define i32 @test9(i32* %P) {
; CHECK-LABEL: @test9(
; CHECK-NEXT: ret i32 0
;
%X = load i32, i32* %P ; <i32> [#uses=1]
%Y = load i32, i32* %P ; <i32> [#uses=1]
%Z = sub i32 %X, %Y ; <i32> [#uses=1]
ret i32 %Z
}
define i32 @test10(i1 %C.upgrd.1, i32* %P, i32* %Q) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: br i1 [[C_UPGRD_1:%.*]], label [[T:%.*]], label [[F:%.*]]
; CHECK: T:
; CHECK-NEXT: store i32 1, i32* [[Q:%.*]], align 4
; CHECK-NEXT: br label [[C:%.*]]
; CHECK: F:
; CHECK-NEXT: br label [[C]]
; CHECK: C:
; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
; CHECK-NEXT: ret i32 0
;
br i1 %C.upgrd.1, label %T, label %F
T: ; preds = %0
store i32 1, i32* %Q
store i32 0, i32* %P
br label %C
F: ; preds = %0
store i32 0, i32* %P
br label %C
C: ; preds = %F, %T
%V = load i32, i32* %P ; <i32> [#uses=1]
ret i32 %V
}
define double @test11(double* %p) {
; CHECK-LABEL: @test11(
; CHECK-NEXT: [[T0:%.*]] = getelementptr double, double* [[P:%.*]], i64 1
; CHECK-NEXT: store double 2.000000e+00, double* [[T0]], align 8
; CHECK-NEXT: ret double 2.000000e+00
;
%t0 = getelementptr double, double* %p, i32 1
store double 2.0, double* %t0
%t1 = getelementptr double, double* %p, i32 1
%x = load double, double* %t1
ret double %x
}
define i32 @test12(i32* %P) {
; CHECK-LABEL: @test12(
; CHECK-NEXT: ret i32 123
;
%A = alloca i32
store i32 123, i32* %A
; Cast the result of the load not the source
%Q = bitcast i32* %A to i32*
%V = load i32, i32* %Q
ret i32 %V
}
define <16 x i8> @test13(<2 x i64> %x) {
; CHECK-LABEL: @test13(
; CHECK-NEXT: ret <16 x i8> zeroinitializer
;
%tmp = load <16 x i8>, <16 x i8>* bitcast ([4 x i32]* @GLOBAL to <16 x i8>*)
ret <16 x i8> %tmp
}
; This test must not have the store of %x forwarded to the load -- there is an
; intervening store if %y. However, the intervening store occurs with a different
; type and size and to a different pointer value. This is ensuring that none of
; those confuse the analysis into thinking that the second store does not alias
; the first.
define i8 @test14(i8 %x, i32 %y) {
; CHECK-LABEL: @test14(
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
; CHECK-NEXT: [[A_I8:%.*]] = bitcast i32* [[A]] to i8*
; CHECK-NEXT: store i8 [[X:%.*]], i8* [[A_I8]], align 4
; CHECK-NEXT: store i32 [[Y:%.*]], i32* [[A]], align 4
; CHECK-NEXT: [[R:%.*]] = load i8, i8* [[A_I8]], align 4
; CHECK-NEXT: ret i8 [[R]]
;
%a = alloca i32
%a.i8 = bitcast i32* %a to i8*
store i8 %x, i8* %a.i8
store i32 %y, i32* %a
%r = load i8, i8* %a.i8
ret i8 %r
}
@test15_global = external global i32
; Same test as @test14 essentially, but using a global instead of an alloca.
define i8 @test15(i8 %x, i32 %y) {
; CHECK-LABEL: @test15(
; CHECK-NEXT: store i8 [[X:%.*]], i8* bitcast (i32* @test15_global to i8*), align 4
; CHECK-NEXT: store i32 [[Y:%.*]], i32* @test15_global, align 4
; CHECK-NEXT: [[R:%.*]] = load i8, i8* bitcast (i32* @test15_global to i8*), align 4
; CHECK-NEXT: ret i8 [[R]]
;
%g.i8 = bitcast i32* @test15_global to i8*
store i8 %x, i8* %g.i8
store i32 %y, i32* @test15_global
%r = load i8, i8* %g.i8
ret i8 %r
}
; Check that we canonicalize loads which are only stored to use integer types
; when there is a valid integer type.
define void @test16(i8* %x, i8* %a, i8* %b, i8* %c) {
; CHECK-LABEL: @test16(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_CAST:%.*]] = bitcast i8* [[C:%.*]] to i32*
; CHECK-NEXT: [[TMP0:%.*]] = bitcast i8* [[X:%.*]] to i32*
; CHECK-NEXT: [[X11:%.*]] = load i32, i32* [[TMP0]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8* [[A:%.*]] to i32*
; CHECK-NEXT: store i32 [[X11]], i32* [[TMP1]], align 4
; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[B:%.*]] to i32*
; CHECK-NEXT: store i32 [[X11]], i32* [[TMP2]], align 4
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i8* [[X]] to i32*
; CHECK-NEXT: [[X22:%.*]] = load i32, i32* [[TMP3]], align 4
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i8* [[B]] to i32*
; CHECK-NEXT: store i32 [[X22]], i32* [[TMP4]], align 4
; CHECK-NEXT: store i32 [[X22]], i32* [[C_CAST]], align 4
; CHECK-NEXT: ret void
;
entry:
%x.cast = bitcast i8* %x to float*
%a.cast = bitcast i8* %a to float*
%b.cast = bitcast i8* %b to float*
%c.cast = bitcast i8* %c to i32*
%x1 = load float, float* %x.cast
store float %x1, float* %a.cast
store float %x1, float* %b.cast
%x2 = load float, float* %x.cast
store float %x2, float* %b.cast
%x2.cast = bitcast float %x2 to i32
store i32 %x2.cast, i32* %c.cast
ret void
}
define void @test16-vect(i8* %x, i8* %a, i8* %b, i8* %c) {
; CHECK-LABEL: @test16-vect(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C_CAST:%.*]] = bitcast i8* [[C:%.*]] to i32*
; CHECK-NEXT: [[TMP0:%.*]] = bitcast i8* [[X:%.*]] to i32*
; CHECK-NEXT: [[X11:%.*]] = load i32, i32* [[TMP0]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8* [[A:%.*]] to i32*
; CHECK-NEXT: store i32 [[X11]], i32* [[TMP1]], align 4
; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[B:%.*]] to i32*
; CHECK-NEXT: store i32 [[X11]], i32* [[TMP2]], align 4
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i8* [[X]] to i32*
; CHECK-NEXT: [[X22:%.*]] = load i32, i32* [[TMP3]], align 4
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i8* [[B]] to i32*
; CHECK-NEXT: store i32 [[X22]], i32* [[TMP4]], align 4
; CHECK-NEXT: store i32 [[X22]], i32* [[C_CAST]], align 4
; CHECK-NEXT: ret void
;
entry:
%x.cast = bitcast i8* %x to <4 x i8>*
%a.cast = bitcast i8* %a to <4 x i8>*
%b.cast = bitcast i8* %b to <4 x i8>*
%c.cast = bitcast i8* %c to i32*
%x1 = load <4 x i8>, <4 x i8>* %x.cast
store <4 x i8> %x1, <4 x i8>* %a.cast
store <4 x i8> %x1, <4 x i8>* %b.cast
%x2 = load <4 x i8>, <4 x i8>* %x.cast
store <4 x i8> %x2, <4 x i8>* %b.cast
%x2.cast = bitcast <4 x i8> %x2 to i32
store i32 %x2.cast, i32* %c.cast
ret void
}
; Check that in cases similar to @test16 we don't try to rewrite a load when
; its only use is a store but it is used as the pointer to that store rather
; than the value.
define void @test17(i8** %x, i8 %y) {
; CHECK-LABEL: @test17(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[X_LOAD:%.*]] = load i8*, i8** [[X:%.*]], align 8
; CHECK-NEXT: store i8 [[Y:%.*]], i8* [[X_LOAD]], align 1
; CHECK-NEXT: ret void
;
entry:
%x.load = load i8*, i8** %x
store i8 %y, i8* %x.load
ret void
}
; Check that we don't try change the type of the load by inserting a bitcast
; generating invalid IR.
%swift.error = type opaque
declare void @useSwiftError(%swift.error** swifterror)
define void @test18(%swift.error** swifterror %err) {
; CHECK-LABEL: @test18(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[SWIFTERROR:%.*]] = alloca swifterror %swift.error*, align 8
; CHECK-NEXT: store %swift.error* null, %swift.error** [[SWIFTERROR]], align 8
; CHECK-NEXT: call void @useSwiftError(%swift.error** nonnull swifterror [[SWIFTERROR]])
; CHECK-NEXT: [[ERR_RES:%.*]] = load %swift.error*, %swift.error** [[SWIFTERROR]], align 8
; CHECK-NEXT: store %swift.error* [[ERR_RES]], %swift.error** [[ERR:%.*]], align 8
; CHECK-NEXT: ret void
;
entry:
%swifterror = alloca swifterror %swift.error*, align 8
store %swift.error* null, %swift.error** %swifterror, align 8
call void @useSwiftError(%swift.error** nonnull swifterror %swifterror)
%err.res = load %swift.error*, %swift.error** %swifterror, align 8
store %swift.error* %err.res, %swift.error** %err, align 8
ret void
}
; Make sure we preseve the type of the store to a swifterror pointer.
declare void @initi8(i8**)
define void @test19(%swift.error** swifterror %err) {
; CHECK-LABEL: @test19(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP:%.*]] = alloca i8*, align 8
; CHECK-NEXT: call void @initi8(i8** nonnull [[TMP]])
; CHECK-NEXT: [[SWIFTERROR:%.*]] = bitcast i8** [[TMP]] to %swift.error**
; CHECK-NEXT: [[ERR_RES:%.*]] = load %swift.error*, %swift.error** [[SWIFTERROR]], align 8
; CHECK-NEXT: store %swift.error* [[ERR_RES]], %swift.error** [[ERR:%.*]], align 8
; CHECK-NEXT: ret void
;
entry:
%tmp = alloca i8*, align 8
call void @initi8(i8** %tmp)
%swifterror = bitcast i8** %tmp to %swift.error**
%err.res = load %swift.error*, %swift.error** %swifterror, align 8
store %swift.error* %err.res, %swift.error** %err, align 8
ret void
}
; Make sure we don't canonicalize accesses to scalable vectors.
define void @test20(<vscale x 4 x i8>* %x, <vscale x 4 x i8>* %y) {
; CHECK-LABEL: @test20(
; CHECK-NEXT: [[X_LOAD:%.*]] = load <vscale x 4 x i8>, <vscale x 4 x i8>* [[X:%.*]], align 1
; CHECK-NEXT: store <vscale x 4 x i8> [[X_LOAD]], <vscale x 4 x i8>* [[Y:%.*]], align 1
; CHECK-NEXT: ret void
;
%x.load = load <vscale x 4 x i8>, <vscale x 4 x i8>* %x, align 1
store <vscale x 4 x i8> %x.load, <vscale x 4 x i8>* %y, align 1
ret void
}