blob: af301f118d77a9a0b38c608934403dab98d670bc [file] [log] [blame]
Eric Christophercee313d2019-04-17 04:52:47 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4define i32 @test1(i32 %A) {
5; CHECK-LABEL: @test1(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +00006; CHECK-NEXT: ret i32 [[A:%.*]]
Eric Christophercee313d2019-04-17 04:52:47 +00007;
8 %B = or i32 %A, 0
9 ret i32 %B
10}
11
12define i32 @all_ones(i32 %A) {
13; CHECK-LABEL: @all_ones(
14; CHECK-NEXT: ret i32 -1
15;
16 %B = or i32 %A, -1
17 ret i32 %B
18}
19
20define <3 x i8> @all_ones_vec_with_undef_elt(<3 x i8> %A) {
21; CHECK-LABEL: @all_ones_vec_with_undef_elt(
22; CHECK-NEXT: ret <3 x i8> <i8 -1, i8 -1, i8 -1>
23;
24 %B = or <3 x i8> %A, <i8 -1, i8 undef, i8 -1>
25 ret <3 x i8> %B
26}
27
28define i1 @test3(i1 %A) {
29; CHECK-LABEL: @test3(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +000030; CHECK-NEXT: ret i1 [[A:%.*]]
Eric Christophercee313d2019-04-17 04:52:47 +000031;
32 %B = or i1 %A, false
33 ret i1 %B
34}
35
36define i1 @test4(i1 %A) {
37; CHECK-LABEL: @test4(
38; CHECK-NEXT: ret i1 true
39;
40 %B = or i1 %A, true
41 ret i1 %B
42}
43
44define i1 @test5(i1 %A) {
45; CHECK-LABEL: @test5(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +000046; CHECK-NEXT: ret i1 [[A:%.*]]
Eric Christophercee313d2019-04-17 04:52:47 +000047;
48 %B = or i1 %A, %A
49 ret i1 %B
50}
51
52define i32 @test6(i32 %A) {
53; CHECK-LABEL: @test6(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +000054; CHECK-NEXT: ret i32 [[A:%.*]]
Eric Christophercee313d2019-04-17 04:52:47 +000055;
56 %B = or i32 %A, %A
57 ret i32 %B
58}
59
60; A | ~A == -1
61define i32 @test7(i32 %A) {
62; CHECK-LABEL: @test7(
63; CHECK-NEXT: ret i32 -1
64;
65 %NotA = xor i32 %A, -1
66 %B = or i32 %A, %NotA
67 ret i32 %B
68}
69
70define i8 @test8(i8 %A) {
71; CHECK-LABEL: @test8(
72; CHECK-NEXT: ret i8 -1
73;
74 %B = or i8 %A, -2
75 %C = or i8 %B, 1
76 ret i8 %C
77}
78
79; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
80define i8 @test9(i8 %A, i8 %B) {
81; CHECK-LABEL: @test9(
82; CHECK-NEXT: ret i8 -1
83;
84 %C = or i8 %A, 1
85 %D = or i8 %B, -2
86 %E = or i8 %C, %D
87 ret i8 %E
88}
89
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +000090; (X & C1) | C2 --> (X | C2) & (C1|C2)
Eric Christophercee313d2019-04-17 04:52:47 +000091define i8 @test10(i8 %A) {
92; CHECK-LABEL: @test10(
93; CHECK-NEXT: ret i8 -2
94;
95 %B = or i8 %A, 1
96 %C = and i8 %B, -2
Eric Christophercee313d2019-04-17 04:52:47 +000097 %D = or i8 %C, -2
98 ret i8 %D
99}
100
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000101; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
Eric Christophercee313d2019-04-17 04:52:47 +0000102define i8 @test11(i8 %A) {
103; CHECK-LABEL: @test11(
104; CHECK-NEXT: ret i8 -1
105;
106 %B = or i8 %A, -2
107 %C = xor i8 %B, 13
Eric Christophercee313d2019-04-17 04:52:47 +0000108 %D = or i8 %C, 1
109 %E = xor i8 %D, 12
110 ret i8 %E
111}
112
Simon Pilgrim47ce1402020-03-18 19:12:43 +0000113define i8 @test11v(<2 x i8> %A) {
114; CHECK-LABEL: @test11v(
115; CHECK-NEXT: [[B:%.*]] = or <2 x i8> [[A:%.*]], <i8 -2, i8 0>
116; CHECK-NEXT: [[CV:%.*]] = xor <2 x i8> [[B]], <i8 13, i8 13>
117; CHECK-NEXT: [[C:%.*]] = extractelement <2 x i8> [[CV]], i32 0
118; CHECK-NEXT: [[D:%.*]] = or i8 [[C]], 1
119; CHECK-NEXT: [[E:%.*]] = xor i8 [[D]], 12
120; CHECK-NEXT: ret i8 [[E]]
121;
122 %B = or <2 x i8> %A, <i8 -2, i8 0>
123 %CV = xor <2 x i8> %B, <i8 13, i8 13>
124 %C = extractelement <2 x i8> %CV, i32 0
125 %D = or i8 %C, 1
126 %E = xor i8 %D, 12
127 ret i8 %E
128}
129
Eric Christophercee313d2019-04-17 04:52:47 +0000130; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000131; If we have: ((V + N) & C1) | (V & C2)
132; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
133; replace with V+N.
Eric Christophercee313d2019-04-17 04:52:47 +0000134define i39 @test1_apint(i39 %V, i39 %M) {
135; CHECK-LABEL: @test1_apint(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000136; CHECK-NEXT: [[N:%.*]] = and i39 [[M:%.*]], -274877906944
137; CHECK-NEXT: [[A:%.*]] = add i39 [[V:%.*]], [[N]]
Eric Christophercee313d2019-04-17 04:52:47 +0000138; CHECK-NEXT: ret i39 [[A]]
139;
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000140 %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943
141 %N = and i39 %M, 274877906944
142 %A = add i39 %V, %N
143 %B = and i39 %A, %C1
144 %D = and i39 %V, 274877906943
145 %R = or i39 %B, %D
146 ret i39 %R
Eric Christophercee313d2019-04-17 04:52:47 +0000147}
148
149define i7 @test2_apint(i7 %X) {
150; CHECK-LABEL: @test2_apint(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000151; CHECK-NEXT: ret i7 [[X:%.*]]
Eric Christophercee313d2019-04-17 04:52:47 +0000152;
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000153 %Y = or i7 %X, 0
154 ret i7 %Y
Eric Christophercee313d2019-04-17 04:52:47 +0000155}
156
157define i17 @test3_apint(i17 %X) {
158; CHECK-LABEL: @test3_apint(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000159; CHECK-NEXT: ret i17 -1
Eric Christophercee313d2019-04-17 04:52:47 +0000160;
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000161 %Y = or i17 %X, -1
162 ret i17 %Y
Eric Christophercee313d2019-04-17 04:52:47 +0000163}
164
165; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000166; If we have: ((V + N) & C1) | (V & C2)
167; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
168; replace with V+N.
Eric Christophercee313d2019-04-17 04:52:47 +0000169define i399 @test4_apint(i399 %V, i399 %M) {
170; CHECK-LABEL: @test4_apint(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000171; CHECK-NEXT: [[N:%.*]] = and i399 [[M:%.*]], 18446742974197923840
172; CHECK-NEXT: [[A:%.*]] = add i399 [[V:%.*]], [[N]]
Eric Christophercee313d2019-04-17 04:52:47 +0000173; CHECK-NEXT: ret i399 [[A]]
174;
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000175 %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943
176 %N = and i399 %M, 18446742974197923840
177 %A = add i399 %V, %N
178 %B = and i399 %A, %C1
179 %D = and i399 %V, 274877906943
180 %R = or i399 %D, %B
181 ret i399 %R
Eric Christophercee313d2019-04-17 04:52:47 +0000182}
183
184define i777 @test5_apint(i777 %X) {
185; CHECK-LABEL: @test5_apint(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000186; CHECK-NEXT: ret i777 [[X:%.*]]
Eric Christophercee313d2019-04-17 04:52:47 +0000187;
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000188 %Y = or i777 %X, 0
189 ret i777 %Y
Eric Christophercee313d2019-04-17 04:52:47 +0000190}
191
192define i117 @test6_apint(i117 %X) {
193; CHECK-LABEL: @test6_apint(
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000194; CHECK-NEXT: ret i117 -1
Eric Christophercee313d2019-04-17 04:52:47 +0000195;
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000196 %Y = or i117 %X, -1
197 ret i117 %Y
Eric Christophercee313d2019-04-17 04:52:47 +0000198}
199
200; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
201; Vector version of test1_apint with the add commuted
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000202; If we have: ((V + N) & C1) | (V & C2)
203; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
204; replace with V+N.
Eric Christophercee313d2019-04-17 04:52:47 +0000205define <2 x i39> @test7_apint(<2 x i39> %V, <2 x i39> %M) {
206; CHECK-LABEL: @test7_apint(
207; CHECK-NEXT: [[N:%.*]] = and <2 x i39> [[M:%.*]], <i39 -274877906944, i39 -274877906944>
208; CHECK-NEXT: [[A:%.*]] = add <2 x i39> [[N]], [[V:%.*]]
209; CHECK-NEXT: ret <2 x i39> [[A]]
210;
Eric Christophercee313d2019-04-17 04:52:47 +0000211 %C1 = xor <2 x i39> <i39 274877906943, i39 274877906943>, <i39 -1, i39 -1> ;; C2 = 274877906943
212 %N = and <2 x i39> %M, <i39 274877906944, i39 274877906944>
213 %A = add <2 x i39> %N, %V
214 %B = and <2 x i39> %A, %C1
215 %D = and <2 x i39> %V, <i39 274877906943, i39 274877906943>
216 %R = or <2 x i39> %B, %D
217 ret <2 x i39> %R
218}
219
220; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
221; Vector version of test4_apint with the add and the or commuted
Simon Pilgrim6bdb0ef2020-03-18 19:02:44 +0000222; If we have: ((V + N) & C1) | (V & C2)
223; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
224; replace with V+N.
Eric Christophercee313d2019-04-17 04:52:47 +0000225define <2 x i399> @test8_apint(<2 x i399> %V, <2 x i399> %M) {
226; CHECK-LABEL: @test8_apint(
227; CHECK-NEXT: [[N:%.*]] = and <2 x i399> [[M:%.*]], <i399 18446742974197923840, i399 18446742974197923840>
228; CHECK-NEXT: [[A:%.*]] = add <2 x i399> [[N]], [[V:%.*]]
229; CHECK-NEXT: ret <2 x i399> [[A]]
230;
Eric Christophercee313d2019-04-17 04:52:47 +0000231 %C1 = xor <2 x i399> <i399 274877906943, i399 274877906943>, <i399 -1, i399 -1> ;; C2 = 274877906943
232 %N = and <2 x i399> %M, <i399 18446742974197923840, i399 18446742974197923840>
233 %A = add <2 x i399> %N, %V
234 %B = and <2 x i399> %A, %C1
235 %D = and <2 x i399> %V, <i399 274877906943, i399 274877906943>
236 %R = or <2 x i399> %D, %B
237 ret <2 x i399> %R
238}