• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; This test makes sure that these instructions are properly eliminated.
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
5
6define i32 @test1(i32 %A) {
7        %B = or i32 %A, 0
8        ret i32 %B
9; CHECK: @test1
10; CHECK: ret i32 %A
11}
12
13define i32 @test2(i32 %A) {
14        %B = or i32 %A, -1
15        ret i32 %B
16; CHECK: @test2
17; CHECK: ret i32 -1
18}
19
20define i8 @test2a(i8 %A) {
21        %B = or i8 %A, -1
22        ret i8 %B
23; CHECK: @test2a
24; CHECK: ret i8 -1
25}
26
27define i1 @test3(i1 %A) {
28        %B = or i1 %A, false
29        ret i1 %B
30; CHECK: @test3
31; CHECK: ret i1 %A
32}
33
34define i1 @test4(i1 %A) {
35        %B = or i1 %A, true
36        ret i1 %B
37; CHECK: @test4
38; CHECK: ret i1 true
39}
40
41define i1 @test5(i1 %A) {
42        %B = or i1 %A, %A
43        ret i1 %B
44; CHECK: @test5
45; CHECK: ret i1 %A
46}
47
48define i32 @test6(i32 %A) {
49        %B = or i32 %A, %A
50        ret i32 %B
51; CHECK: @test6
52; CHECK: ret i32 %A
53}
54
55; A | ~A == -1
56define i32 @test7(i32 %A) {
57        %NotA = xor i32 -1, %A
58        %B = or i32 %A, %NotA
59        ret i32 %B
60; CHECK: @test7
61; CHECK: ret i32 -1
62}
63
64define i8 @test8(i8 %A) {
65        %B = or i8 %A, -2
66        %C = or i8 %B, 1
67        ret i8 %C
68; CHECK: @test8
69; CHECK: ret i8 -1
70}
71
72; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
73define i8 @test9(i8 %A, i8 %B) {
74        %C = or i8 %A, 1
75        %D = or i8 %B, -2
76        %E = or i8 %C, %D
77        ret i8 %E
78; CHECK: @test9
79; CHECK: ret i8 -1
80}
81
82define i8 @test10(i8 %A) {
83        %B = or i8 %A, 1
84        %C = and i8 %B, -2
85        ; (X & C1) | C2 --> (X | C2) & (C1|C2)
86        %D = or i8 %C, -2
87        ret i8 %D
88; CHECK: @test10
89; CHECK: ret i8 -2
90}
91
92define i8 @test11(i8 %A) {
93        %B = or i8 %A, -2
94        %C = xor i8 %B, 13
95        ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
96        %D = or i8 %C, 1
97        %E = xor i8 %D, 12
98        ret i8 %E
99; CHECK: @test11
100; CHECK: ret i8 -1
101}
102
103define i32 @test12(i32 %A) {
104        ; Should be eliminated
105        %B = or i32 %A, 4
106        %C = and i32 %B, 8
107        ret i32 %C
108; CHECK: @test12
109; CHECK: %C = and i32 %A, 8
110; CHECK: ret i32 %C
111}
112
113define i32 @test13(i32 %A) {
114        %B = or i32 %A, 12
115        ; Always equal to 8
116        %C = and i32 %B, 8
117        ret i32 %C
118; CHECK: @test13
119; CHECK: ret i32 8
120}
121
122define i1 @test14(i32 %A, i32 %B) {
123        %C1 = icmp ult i32 %A, %B
124        %C2 = icmp ugt i32 %A, %B
125        ; (A < B) | (A > B) === A != B
126        %D = or i1 %C1, %C2
127        ret i1 %D
128; CHECK: @test14
129; CHECK: icmp ne i32 %A, %B
130; CHECK: ret i1
131}
132
133define i1 @test15(i32 %A, i32 %B) {
134        %C1 = icmp ult i32 %A, %B
135        %C2 = icmp eq i32 %A, %B
136        ; (A < B) | (A == B) === A <= B
137        %D = or i1 %C1, %C2
138        ret i1 %D
139; CHECK: @test15
140; CHECK:  icmp ule i32 %A, %B
141; CHECK: ret i1
142}
143
144define i32 @test16(i32 %A) {
145        %B = and i32 %A, 1
146        ; -2 = ~1
147        %C = and i32 %A, -2
148        ; %D = and int %B, -1 == %B
149        %D = or i32 %B, %C
150        ret i32 %D
151; CHECK: @test16
152; CHECK: ret i32 %A
153}
154
155define i32 @test17(i32 %A) {
156        %B = and i32 %A, 1
157        %C = and i32 %A, 4
158        ; %D = and int %B, 5
159        %D = or i32 %B, %C
160        ret i32 %D
161; CHECK: @test17
162; CHECK: %D = and i32 %A, 5
163; CHECK: ret i32 %D
164}
165
166define i1 @test18(i32 %A) {
167        %B = icmp sge i32 %A, 100
168        %C = icmp slt i32 %A, 50
169        ;; (A-50) >u 50
170        %D = or i1 %B, %C
171        ret i1 %D
172; CHECK: @test18
173; CHECK: add i32
174; CHECK:  icmp ugt
175; CHECK: ret i1
176}
177
178define i1 @test19(i32 %A) {
179        %B = icmp eq i32 %A, 50
180        %C = icmp eq i32 %A, 51
181        ;; (A-50) < 2
182        %D = or i1 %B, %C
183        ret i1 %D
184; CHECK: @test19
185; CHECK: add i32
186; CHECK: icmp ult
187; CHECK: ret i1
188}
189
190define i32 @test20(i32 %x) {
191        %y = and i32 %x, 123
192        %z = or i32 %y, %x
193        ret i32 %z
194; CHECK: @test20
195; CHECK: ret i32 %x
196}
197
198define i32 @test21(i32 %tmp.1) {
199        %tmp.1.mask1 = add i32 %tmp.1, 2
200        %tmp.3 = and i32 %tmp.1.mask1, -2
201        %tmp.5 = and i32 %tmp.1, 1
202        ;; add tmp.1, 2
203        %tmp.6 = or i32 %tmp.5, %tmp.3
204        ret i32 %tmp.6
205; CHECK: @test21
206; CHECK:   add i32 %{{[^,]*}}, 2
207; CHECK:   ret i32
208}
209
210define i32 @test22(i32 %B) {
211        %ELIM41 = and i32 %B, 1
212        %ELIM7 = and i32 %B, -2
213        %ELIM5 = or i32 %ELIM41, %ELIM7
214        ret i32 %ELIM5
215; CHECK: @test22
216; CHECK: ret i32 %B
217}
218
219define i16 @test23(i16 %A) {
220        %B = lshr i16 %A, 1
221        ;; fold or into xor
222        %C = or i16 %B, -32768
223        %D = xor i16 %C, 8193
224        ret i16 %D
225; CHECK: @test23
226; CHECK:   %B = lshr i16 %A, 1
227; CHECK:   %D = xor i16 %B, -24575
228; CHECK:   ret i16 %D
229}
230
231; PR1738
232define i1 @test24(double %X, double %Y) {
233        %tmp9 = fcmp uno double %X, 0.000000e+00                ; <i1> [#uses=1]
234        %tmp13 = fcmp uno double %Y, 0.000000e+00               ; <i1> [#uses=1]
235        %bothcond = or i1 %tmp13, %tmp9         ; <i1> [#uses=1]
236        ret i1 %bothcond
237
238; CHECK: @test24
239; CHECK:    = fcmp uno double %Y, %X
240; CHECK:   ret i1
241}
242
243; PR3266 & PR5276
244define i1 @test25(i32 %A, i32 %B) {
245  %C = icmp eq i32 %A, 0
246  %D = icmp eq i32 %B, 57
247  %E = or i1 %C, %D
248  %F = xor i1 %E, -1
249  ret i1 %F
250
251; CHECK: @test25
252; CHECK: icmp ne i32 %A, 0
253; CHECK-NEXT: icmp ne i32 %B, 57
254; CHECK-NEXT:  %F = and i1
255; CHECK-NEXT:  ret i1 %F
256}
257
258; PR5634
259define i1 @test26(i32 %A, i32 %B) {
260        %C1 = icmp eq i32 %A, 0
261        %C2 = icmp eq i32 %B, 0
262        ; (A == 0) & (A == 0)   -->   (A|B) == 0
263        %D = and i1 %C1, %C2
264        ret i1 %D
265; CHECK: @test26
266; CHECK: or i32 %A, %B
267; CHECK: icmp eq i32 {{.*}}, 0
268; CHECK: ret i1
269}
270
271define i1 @test27(i32* %A, i32* %B) {
272  %C1 = ptrtoint i32* %A to i32
273  %C2 = ptrtoint i32* %B to i32
274  %D = or i32 %C1, %C2
275  %E = icmp eq i32 %D, 0
276  ret i1 %E
277; CHECK: @test27
278; CHECK: icmp eq i32* %A, null
279; CHECK: icmp eq i32* %B, null
280; CHECK: and i1
281; CHECK: ret i1
282}
283
284; PR5634
285define i1 @test28(i32 %A, i32 %B) {
286        %C1 = icmp ne i32 %A, 0
287        %C2 = icmp ne i32 %B, 0
288        ; (A != 0) | (A != 0)   -->   (A|B) != 0
289        %D = or i1 %C1, %C2
290        ret i1 %D
291; CHECK: @test28
292; CHECK: or i32 %A, %B
293; CHECK: icmp ne i32 {{.*}}, 0
294; CHECK: ret i1
295}
296
297define i1 @test29(i32* %A, i32* %B) {
298  %C1 = ptrtoint i32* %A to i32
299  %C2 = ptrtoint i32* %B to i32
300  %D = or i32 %C1, %C2
301  %E = icmp ne i32 %D, 0
302  ret i1 %E
303; CHECK: @test29
304; CHECK: icmp ne i32* %A, null
305; CHECK: icmp ne i32* %B, null
306; CHECK: or i1
307; CHECK: ret i1
308}
309
310; PR4216
311define i32 @test30(i32 %A) {
312entry:
313  %B = or i32 %A, 32962
314  %C = and i32 %A, -65536
315  %D = and i32 %B, 40186
316  %E = or i32 %D, %C
317  ret i32 %E
318; CHECK: @test30
319; CHECK: %D = and i32 %A, -58312
320; CHECK: %E = or i32 %D, 32962
321; CHECK: ret i32 %E
322}
323
324; PR4216
325define i64 @test31(i64 %A) nounwind readnone ssp noredzone {
326  %B = or i64 %A, 194
327  %D = and i64 %B, 250
328
329  %C = or i64 %A, 32768
330  %E = and i64 %C, 4294941696
331
332  %F = or i64 %D, %E
333  ret i64 %F
334; CHECK: @test31
335; CHECK-NEXT: %E = and i64 %A, 4294908984
336; CHECK-NEXT: %F = or i64 %E, 32962
337; CHECK-NEXT: ret i64 %F
338}
339
340define <4 x i32> @test32(<4 x i1> %and.i1352, <4 x i32> %vecinit6.i176, <4 x i32> %vecinit6.i191) {
341  %and.i135 = sext <4 x i1> %and.i1352 to <4 x i32> ; <<4 x i32>> [#uses=2]
342  %and.i129 = and <4 x i32> %vecinit6.i176, %and.i135 ; <<4 x i32>> [#uses=1]
343  %neg.i = xor <4 x i32> %and.i135, <i32 -1, i32 -1, i32 -1, i32 -1> ; <<4 x i32>> [#uses=1]
344  %and.i = and <4 x i32> %vecinit6.i191, %neg.i   ; <<4 x i32>> [#uses=1]
345  %or.i = or <4 x i32> %and.i, %and.i129          ; <<4 x i32>> [#uses=1]
346  ret <4 x i32> %or.i
347; Don't turn this into a vector select until codegen matures to handle them
348; better.
349; CHECK: @test32
350; CHECK: or <4 x i32> %and.i, %and.i129
351}
352
353define i1 @test33(i1 %X, i1 %Y) {
354  %a = or i1 %X, %Y
355  %b = or i1 %a, %X
356  ret i1 %b
357; CHECK: @test33
358; CHECK-NEXT: or i1 %X, %Y
359; CHECK-NEXT: ret
360}
361
362define i32 @test34(i32 %X, i32 %Y) {
363  %a = or i32 %X, %Y
364  %b = or i32 %Y, %a
365  ret i32 %b
366; CHECK: @test34
367; CHECK-NEXT: or i32 %X, %Y
368; CHECK-NEXT: ret
369}
370
371define i32 @test35(i32 %a, i32 %b) {
372  %1 = or i32 %a, 1135
373  %2 = or i32 %1, %b
374  ret i32 %2
375  ; CHECK: @test35
376  ; CHECK-NEXT: or i32 %a, %b
377  ; CHECK-NEXT: or i32 %1, 1135
378}
379
380define i1 @test36(i32 %x) {
381  %cmp1 = icmp eq i32 %x, 23
382  %cmp2 = icmp eq i32 %x, 24
383  %ret1 = or i1 %cmp1, %cmp2
384  %cmp3 = icmp eq i32 %x, 25
385  %ret2 = or i1 %ret1, %cmp3
386  ret i1 %ret2
387; CHECK: @test36
388; CHECK-NEXT: %x.off = add i32 %x, -23
389; CHECK-NEXT: icmp ult i32 %x.off, 3
390; CHECK-NEXT: ret i1
391}
392
393define i32 @test37(i32* %xp, i32 %y) {
394; CHECK: @test37
395; CHECK: select i1 %tobool, i32 -1, i32 %x
396  %tobool = icmp ne i32 %y, 0
397  %sext = sext i1 %tobool to i32
398  %x = load i32* %xp
399  %or = or i32 %sext, %x
400  ret i32 %or
401}
402
403define i32 @test38(i32* %xp, i32 %y) {
404; CHECK: @test38
405; CHECK: select i1 %tobool, i32 -1, i32 %x
406  %tobool = icmp ne i32 %y, 0
407  %sext = sext i1 %tobool to i32
408  %x = load i32* %xp
409  %or = or i32 %x, %sext
410  ret i32 %or
411}
412