1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 define i1 @ult_2(i32 %x) {
8 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 254
9 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[TMP1]], 0
10 ; CHECK-NEXT: ret i1 [[R]]
12 %t = trunc i32 %x to i8
13 %r = icmp ult i8 %t, 2
17 define <2 x i1> @ult_16_splat(<2 x i16> %x) {
18 ; CHECK-LABEL: @ult_16_splat(
19 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], <i16 2032, i16 2032>
20 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i16> [[TMP1]], zeroinitializer
21 ; CHECK-NEXT: ret <2 x i1> [[R]]
23 %t = trunc <2 x i16> %x to <2 x i11>
24 %r = icmp ult <2 x i11> %t, <i11 16, i11 16>
28 ; negative test - need power-of-2 constant
30 define i1 @ult_3(i32 %x) {
31 ; CHECK-LABEL: @ult_3(
32 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
33 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T]], 3
34 ; CHECK-NEXT: ret i1 [[R]]
36 %t = trunc i32 %x to i8
37 %r = icmp ult i8 %t, 3
41 ; negative test - no extra use allowed
43 define i1 @ult_2_use(i32 %x) {
44 ; CHECK-LABEL: @ult_2_use(
45 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
46 ; CHECK-NEXT: call void @use(i8 [[T]])
47 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T]], 2
48 ; CHECK-NEXT: ret i1 [[R]]
50 %t = trunc i32 %x to i8
52 %r = icmp ult i8 %t, 2
56 @a = internal unnamed_addr constant [3 x i32] [i32 0, i32 0, i32 1], align 4
58 define i1 @PR52260(i32 %x) {
59 ; CHECK-LABEL: @PR52260(
60 ; CHECK-NEXT: ret i1 true
62 %idxprom = sext i32 %x to i64
63 %idx = getelementptr inbounds [3 x i32], [3 x i32]* @a, i64 0, i64 %idxprom
64 %t1 = load i32, i32* %idx, align 4
65 %conv1 = lshr i32 %t1, 1
66 %t2 = trunc i32 %conv1 to i8
67 %conv2 = and i8 %t2, 127
68 %tobool = icmp eq i8 %conv2, 0
72 define i1 @ult_192(i32 %x) {
73 ; CHECK-LABEL: @ult_192(
74 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 192
75 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[TMP1]], 192
76 ; CHECK-NEXT: ret i1 [[R]]
78 %t = trunc i32 %x to i8
79 %r = icmp ult i8 %t, 192 ; 0b1100_0000
83 define <2 x i1> @ult_2044_splat(<2 x i16> %x) {
84 ; CHECK-LABEL: @ult_2044_splat(
85 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], <i16 2044, i16 2044>
86 ; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i16> [[TMP1]], <i16 2044, i16 2044>
87 ; CHECK-NEXT: ret <2 x i1> [[R]]
89 %t = trunc <2 x i16> %x to <2 x i11>
90 %r = icmp ult <2 x i11> %t, <i11 2044, i11 2044> ; 0b111_1111_1100
94 ; negative test - need high-bit-mask constant
96 define i1 @ult_96(i32 %x) {
97 ; CHECK-LABEL: @ult_96(
98 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
99 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T]], 96
100 ; CHECK-NEXT: ret i1 [[R]]
102 %t = trunc i32 %x to i8
103 %r = icmp ult i8 %t, 96 ; 0b0110_0000
107 ; negative test - no extra use allowed
109 define i1 @ult_192_use(i32 %x) {
110 ; CHECK-LABEL: @ult_192_use(
111 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
112 ; CHECK-NEXT: call void @use(i8 [[T]])
113 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T]], -64
114 ; CHECK-NEXT: ret i1 [[R]]
116 %t = trunc i32 %x to i8
117 call void @use(i8 %t)
118 %r = icmp ult i8 %t, 192
122 define i1 @ugt_3(i32 %x) {
123 ; CHECK-LABEL: @ugt_3(
124 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 252
125 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[TMP1]], 0
126 ; CHECK-NEXT: ret i1 [[R]]
128 %t = trunc i32 %x to i8
129 %r = icmp ugt i8 %t, 3
133 define <2 x i1> @ugt_7_splat(<2 x i16> %x) {
134 ; CHECK-LABEL: @ugt_7_splat(
135 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], <i16 2040, i16 2040>
136 ; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i16> [[TMP1]], zeroinitializer
137 ; CHECK-NEXT: ret <2 x i1> [[R]]
139 %t = trunc <2 x i16> %x to <2 x i11>
140 %r = icmp ugt <2 x i11> %t, <i11 7, i11 7>
144 ; negative test - need low-bit-mask constant
146 define i1 @ugt_4(i32 %x) {
147 ; CHECK-LABEL: @ugt_4(
148 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
149 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 4
150 ; CHECK-NEXT: ret i1 [[R]]
152 %t = trunc i32 %x to i8
153 %r = icmp ugt i8 %t, 4
157 ; negative test - no extra use allowed
159 define i1 @ugt_3_use(i32 %x) {
160 ; CHECK-LABEL: @ugt_3_use(
161 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
162 ; CHECK-NEXT: call void @use(i8 [[T]])
163 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 3
164 ; CHECK-NEXT: ret i1 [[R]]
166 %t = trunc i32 %x to i8
167 call void @use(i8 %t)
168 %r = icmp ugt i8 %t, 3
172 define i1 @ugt_253(i32 %x) {
173 ; CHECK-LABEL: @ugt_253(
174 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 254
175 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[TMP1]], 254
176 ; CHECK-NEXT: ret i1 [[R]]
178 %t = trunc i32 %x to i8
179 %r = icmp ugt i8 %t, 253
183 define <2 x i1> @ugt_2043_splat(<2 x i16> %x) {
184 ; CHECK-LABEL: @ugt_2043_splat(
185 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], <i16 2044, i16 2044>
186 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i16> [[TMP1]], <i16 2044, i16 2044>
187 ; CHECK-NEXT: ret <2 x i1> [[R]]
189 %t = trunc <2 x i16> %x to <2 x i11>
190 %r = icmp ugt <2 x i11> %t, <i11 2043, i11 2043> ; 0b111_1111_101
194 ; negative test - need not-of-power-of-2 constant
196 define i1 @ugt_252(i32 %x) {
197 ; CHECK-LABEL: @ugt_252(
198 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
199 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], -4
200 ; CHECK-NEXT: ret i1 [[R]]
202 %t = trunc i32 %x to i8
203 %r = icmp ugt i8 %t, 252
207 ; negative test - no extra use allowed
209 define i1 @ugt_253_use(i32 %x) {
210 ; CHECK-LABEL: @ugt_253_use(
211 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
212 ; CHECK-NEXT: call void @use(i8 [[T]])
213 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], -3
214 ; CHECK-NEXT: ret i1 [[R]]
216 %t = trunc i32 %x to i8
217 call void @use(i8 %t)
218 %r = icmp ugt i8 %t, 253
222 define i1 @slt_0(i32 %x) {
223 ; CHECK-LABEL: @slt_0(
224 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 128
225 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[TMP1]], 0
226 ; CHECK-NEXT: ret i1 [[R]]
228 %t = trunc i32 %x to i8
229 %r = icmp slt i8 %t, 0
233 define <2 x i1> @slt_0_splat(<2 x i16> %x) {
234 ; CHECK-LABEL: @slt_0_splat(
235 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], <i16 1024, i16 1024>
236 ; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i16> [[TMP1]], zeroinitializer
237 ; CHECK-NEXT: ret <2 x i1> [[R]]
239 %t = trunc <2 x i16> %x to <2 x i11>
240 %r = icmp slt <2 x i11> %t, zeroinitializer
244 define i1 @slt_1(i32 %x) {
245 ; CHECK-LABEL: @slt_1(
246 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
247 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[T]], 1
248 ; CHECK-NEXT: ret i1 [[R]]
250 %t = trunc i32 %x to i8
251 %r = icmp slt i8 %t, 1
255 define i1 @slt_0_use(i32 %x) {
256 ; CHECK-LABEL: @slt_0_use(
257 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
258 ; CHECK-NEXT: call void @use(i8 [[T]])
259 ; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[T]], 0
260 ; CHECK-NEXT: ret i1 [[R]]
262 %t = trunc i32 %x to i8
263 call void @use(i8 %t)
264 %r = icmp slt i8 %t, 0
268 define i1 @sgt_n1(i32 %x) {
269 ; CHECK-LABEL: @sgt_n1(
270 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 128
271 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[TMP1]], 0
272 ; CHECK-NEXT: ret i1 [[R]]
274 %t = trunc i32 %x to i8
275 %r = icmp sgt i8 %t, -1
279 define <2 x i1> @sgt_n1_splat(<2 x i16> %x) {
280 ; CHECK-LABEL: @sgt_n1_splat(
281 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], <i16 1024, i16 1024>
282 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i16> [[TMP1]], zeroinitializer
283 ; CHECK-NEXT: ret <2 x i1> [[R]]
285 %t = trunc <2 x i16> %x to <2 x i11>
286 %r = icmp sgt <2 x i11> %t, <i11 -1, i11 -1>
290 define i1 @sgt_0(i32 %x) {
291 ; CHECK-LABEL: @sgt_0(
292 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
293 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[T]], 0
294 ; CHECK-NEXT: ret i1 [[R]]
296 %t = trunc i32 %x to i8
297 %r = icmp sgt i8 %t, 0
301 define i1 @sgt_n1_use(i32 %x) {
302 ; CHECK-LABEL: @sgt_n1_use(
303 ; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
304 ; CHECK-NEXT: call void @use(i8 [[T]])
305 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[T]], -1
306 ; CHECK-NEXT: ret i1 [[R]]
308 %t = trunc i32 %x to i8
309 call void @use(i8 %t)
310 %r = icmp sgt i8 %t, -1