blob: 46e79a258e230908c46ca434fb51e8bbe41dfdde [file] [log] [blame]
Sanjay Patel8a2bf302016-07-18 20:06:51 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
David Majnemerc6a5e1d2014-11-27 06:32:46 +00002; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4define i32 @test1(i32 %x) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +00005; CHECK-LABEL: @test1(
6; CHECK-NEXT: ret i32 %x
7;
David Majnemerc6a5e1d2014-11-27 06:32:46 +00008 %and = and i32 %x, 1
9 %cmp = icmp eq i32 %and, 0
10 %and1 = and i32 %x, -2
11 %and1.x = select i1 %cmp, i32 %and1, i32 %x
12 ret i32 %and1.x
David Majnemerc6a5e1d2014-11-27 06:32:46 +000013}
14
15define i32 @test2(i32 %x) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +000016; CHECK-LABEL: @test2(
17; CHECK-NEXT: ret i32 %x
18;
David Majnemerc6a5e1d2014-11-27 06:32:46 +000019 %and = and i32 %x, 1
20 %cmp = icmp ne i32 %and, 0
21 %and1 = and i32 %x, -2
22 %and1.x = select i1 %cmp, i32 %x, i32 %and1
23 ret i32 %and1.x
David Majnemerc6a5e1d2014-11-27 06:32:46 +000024}
25
26define i32 @test3(i32 %x) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +000027; CHECK-LABEL: @test3(
28; CHECK-NEXT: [[AND1:%.*]] = and i32 %x, -2
29; CHECK-NEXT: ret i32 [[AND1]]
30;
David Majnemerc6a5e1d2014-11-27 06:32:46 +000031 %and = and i32 %x, 1
32 %cmp = icmp ne i32 %and, 0
33 %and1 = and i32 %x, -2
34 %and1.x = select i1 %cmp, i32 %and1, i32 %x
35 ret i32 %and1.x
David Majnemerc6a5e1d2014-11-27 06:32:46 +000036}
37
David Majnemer0b6a0b02014-12-20 03:04:38 +000038define i32 @test4(i32 %X) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +000039; CHECK-LABEL: @test4(
40; CHECK-NEXT: [[OR:%.*]] = or i32 %X, -2147483648
41; CHECK-NEXT: ret i32 [[OR]]
42;
David Majnemer0b6a0b02014-12-20 03:04:38 +000043 %cmp = icmp slt i32 %X, 0
44 %or = or i32 %X, -2147483648
45 %cond = select i1 %cmp, i32 %X, i32 %or
46 ret i32 %cond
David Majnemer0b6a0b02014-12-20 03:04:38 +000047}
48
49define i32 @test5(i32 %X) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +000050; CHECK-LABEL: @test5(
51; CHECK-NEXT: ret i32 %X
52;
David Majnemer0b6a0b02014-12-20 03:04:38 +000053 %cmp = icmp slt i32 %X, 0
54 %or = or i32 %X, -2147483648
55 %cond = select i1 %cmp, i32 %or, i32 %X
56 ret i32 %cond
David Majnemer0b6a0b02014-12-20 03:04:38 +000057}
58
59define i32 @test6(i32 %X) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +000060; CHECK-LABEL: @test6(
61; CHECK-NEXT: [[AND:%.*]] = and i32 %X, 2147483647
62; CHECK-NEXT: ret i32 [[AND]]
63;
David Majnemer0b6a0b02014-12-20 03:04:38 +000064 %cmp = icmp slt i32 %X, 0
65 %and = and i32 %X, 2147483647
66 %cond = select i1 %cmp, i32 %and, i32 %X
67 ret i32 %cond
David Majnemer0b6a0b02014-12-20 03:04:38 +000068}
69
70define i32 @test7(i32 %X) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +000071; CHECK-LABEL: @test7(
72; CHECK-NEXT: ret i32 %X
73;
David Majnemer0b6a0b02014-12-20 03:04:38 +000074 %cmp = icmp slt i32 %X, 0
75 %and = and i32 %X, 2147483647
76 %cond = select i1 %cmp, i32 %X, i32 %and
77 ret i32 %cond
David Majnemer0b6a0b02014-12-20 03:04:38 +000078}
79
80define i32 @test8(i32 %X) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +000081; CHECK-LABEL: @test8(
82; CHECK-NEXT: ret i32 %X
83;
David Majnemer0b6a0b02014-12-20 03:04:38 +000084 %cmp = icmp sgt i32 %X, -1
85 %or = or i32 %X, -2147483648
86 %cond = select i1 %cmp, i32 %X, i32 %or
87 ret i32 %cond
David Majnemer0b6a0b02014-12-20 03:04:38 +000088}
89
90define i32 @test9(i32 %X) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +000091; CHECK-LABEL: @test9(
92; CHECK-NEXT: [[OR:%.*]] = or i32 %X, -2147483648
93; CHECK-NEXT: ret i32 [[OR]]
94;
David Majnemer0b6a0b02014-12-20 03:04:38 +000095 %cmp = icmp sgt i32 %X, -1
96 %or = or i32 %X, -2147483648
97 %cond = select i1 %cmp, i32 %or, i32 %X
98 ret i32 %cond
David Majnemer0b6a0b02014-12-20 03:04:38 +000099}
100
101define i32 @test10(i32 %X) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +0000102; CHECK-LABEL: @test10(
103; CHECK-NEXT: ret i32 %X
104;
David Majnemer0b6a0b02014-12-20 03:04:38 +0000105 %cmp = icmp sgt i32 %X, -1
106 %and = and i32 %X, 2147483647
107 %cond = select i1 %cmp, i32 %and, i32 %X
108 ret i32 %cond
David Majnemer0b6a0b02014-12-20 03:04:38 +0000109}
110
111define i32 @test11(i32 %X) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +0000112; CHECK-LABEL: @test11(
113; CHECK-NEXT: [[AND:%.*]] = and i32 %X, 2147483647
114; CHECK-NEXT: ret i32 [[AND]]
115;
David Majnemer0b6a0b02014-12-20 03:04:38 +0000116 %cmp = icmp sgt i32 %X, -1
117 %and = and i32 %X, 2147483647
118 %cond = select i1 %cmp, i32 %X, i32 %and
119 ret i32 %cond
David Majnemer0b6a0b02014-12-20 03:04:38 +0000120}
121
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000122define i32 @select_icmp_and_8_eq_0_or_8(i32 %x) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +0000123; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8(
124; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 8
125; CHECK-NEXT: ret i32 [[OR]]
126;
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000127 %and = and i32 %x, 8
128 %cmp = icmp eq i32 %and, 0
129 %or = or i32 %x, 8
130 %or.x = select i1 %cmp, i32 %or, i32 %x
131 ret i32 %or.x
132}
133
Sanjay Pateld2ff6d72016-07-19 16:49:55 +0000134; PR28466: https://llvm.org/bugs/show_bug.cgi?id=28466
Sanjay Patel8b76ebe2016-07-19 17:07:35 +0000135
136define i32 @select_icmp_trunc_8_eq_0_or_8(i32 %x) {
137; CHECK-LABEL: @select_icmp_trunc_8_eq_0_or_8(
138; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i8
139; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TRUNC]], 0
140; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 128
141; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[OR]], i32 %x
142; CHECK-NEXT: ret i32 [[SEL]]
143;
144 %trunc = trunc i32 %x to i8
145 %cmp = icmp slt i8 %trunc, 0
146 %or = or i32 %x, 128
147 %sel = select i1 %cmp, i32 %or, i32 %x
148 ret i32 %sel
149}
Sanjay Pateld2ff6d72016-07-19 16:49:55 +0000150
151define i32 @select_icmp_and_8_ne_0_or_128(i32 %x) {
152; CHECK-LABEL: @select_icmp_and_8_ne_0_or_128(
153; CHECK-NEXT: ret i32 %x
154;
155 %and = and i32 %x, 128
156 %cmp = icmp eq i32 %and, 0
157 %or = or i32 %x, 128
158 %or.x = select i1 %cmp, i32 %x, i32 %or
159 ret i32 %or.x
160}
161
Sanjay Patel8b76ebe2016-07-19 17:07:35 +0000162define i32 @select_icmp_trunc_8_ne_0_or_128(i32 %x) {
163; CHECK-LABEL: @select_icmp_trunc_8_ne_0_or_128(
164; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i8
165; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TRUNC]], 0
166; CHECK-NEXT: [[OR:%.*]] = or i32 %x, 128
167; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 [[OR]]
168; CHECK-NEXT: ret i32 [[SEL]]
169;
170 %trunc = trunc i32 %x to i8
171 %cmp = icmp slt i8 %trunc, 0
172 %or = or i32 %x, 128
173 %sel = select i1 %cmp, i32 %x, i32 %or
174 ret i32 %sel
175}
176
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000177define i32 @select_icmp_and_8_ne_0_and_not_8(i32 %x) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +0000178; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8(
179; CHECK-NEXT: [[AND1:%.*]] = and i32 %x, -9
180; CHECK-NEXT: ret i32 [[AND1]]
181;
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000182 %and = and i32 %x, 8
183 %cmp = icmp eq i32 %and, 0
184 %and1 = and i32 %x, -9
185 %x.and1 = select i1 %cmp, i32 %x, i32 %and1
186 ret i32 %x.and1
187}
188
Sanjay Patel8b76ebe2016-07-19 17:07:35 +0000189define i32 @select_icmp_trunc_8_ne_0_and_not_8(i32 %x) {
190; CHECK-LABEL: @select_icmp_trunc_8_ne_0_and_not_8(
191; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i4
192; CHECK-NEXT: [[CMP:%.*]] = icmp slt i4 [[TRUNC]], 0
193; CHECK-NEXT: [[AND:%.*]] = and i32 %x, -9
194; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 [[AND]]
195; CHECK-NEXT: ret i32 [[SEL]]
196;
197 %trunc = trunc i32 %x to i4
198 %cmp = icmp slt i4 %trunc, 0
199 %and = and i32 %x, -9
200 %sel = select i1 %cmp, i32 %x, i32 %and
201 ret i32 %sel
202}
203
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000204define i32 @select_icmp_and_8_eq_0_and_not_8(i32 %x) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +0000205; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8(
206; CHECK-NEXT: ret i32 %x
207;
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000208 %and = and i32 %x, 8
209 %cmp = icmp eq i32 %and, 0
210 %and1 = and i32 %x, -9
211 %and1.x = select i1 %cmp, i32 %and1, i32 %x
212 ret i32 %and1.x
213}
214
Sanjay Patel8b76ebe2016-07-19 17:07:35 +0000215define i32 @select_icmp_trunc_8_eq_0_and_not_8(i32 %x) {
216; CHECK-LABEL: @select_icmp_trunc_8_eq_0_and_not_8(
217; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %x to i4
218; CHECK-NEXT: [[CMP:%.*]] = icmp slt i4 [[TRUNC]], 0
219; CHECK-NEXT: [[AND:%.*]] = and i32 %x, -9
220; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[AND]], i32 %x
221; CHECK-NEXT: ret i32 [[SEL]]
222;
223 %trunc = trunc i32 %x to i4
224 %cmp = icmp slt i4 %trunc, 0
225 %and = and i32 %x, -9
226 %sel = select i1 %cmp, i32 %and, i32 %x
227 ret i32 %sel
228}
229
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000230define i64 @select_icmp_x_and_8_eq_0_y_and_not_8(i32 %x, i64 %y) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +0000231; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_and_not_8(
232; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 8
233; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
234; CHECK-NEXT: [[AND1:%.*]] = and i64 %y, -9
235; CHECK-NEXT: [[Y_AND1:%.*]] = select i1 [[CMP]], i64 %y, i64 [[AND1]]
236; CHECK-NEXT: ret i64 [[Y_AND1]]
237;
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000238 %and = and i32 %x, 8
239 %cmp = icmp eq i32 %and, 0
240 %and1 = and i64 %y, -9
241 %y.and1 = select i1 %cmp, i64 %y, i64 %and1
242 ret i64 %y.and1
243}
244
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000245define i64 @select_icmp_x_and_8_ne_0_y_and_not_8(i32 %x, i64 %y) {
Sanjay Patel8a2bf302016-07-18 20:06:51 +0000246; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8(
247; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 8
248; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
249; CHECK-NEXT: [[AND1:%.*]] = and i64 %y, -9
250; CHECK-NEXT: [[AND1_Y:%.*]] = select i1 [[CMP]], i64 [[AND1]], i64 %y
251; CHECK-NEXT: ret i64 [[AND1_Y]]
252;
David Majnemerc6a5e1d2014-11-27 06:32:46 +0000253 %and = and i32 %x, 8
254 %cmp = icmp eq i32 %and, 0
255 %and1 = and i64 %y, -9
256 %and1.y = select i1 %cmp, i64 %and1, i64 %y
257 ret i64 %and1.y
258}
259