xref: /llvm-project/llvm/test/Transforms/InstCombine/binop-itofp.ll (revision eb7ad8853cfe6ede2d592a417a1ec64636a61bb5)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3
4define half @test_ui_ui_i8_add(i8 noundef %x_in, i8 noundef %y_in) {
5; CHECK-LABEL: @test_ui_ui_i8_add(
6; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 127
7; CHECK-NEXT:    [[Y:%.*]] = and i8 [[Y_IN:%.*]], 127
8; CHECK-NEXT:    [[TMP1:%.*]] = add nuw i8 [[X]], [[Y]]
9; CHECK-NEXT:    [[R:%.*]] = uitofp i8 [[TMP1]] to half
10; CHECK-NEXT:    ret half [[R]]
11;
12  %x = and i8 %x_in, 127
13  %y = and i8 %y_in, 127
14  %xf = uitofp i8 %x to half
15  %yf = uitofp i8 %y to half
16  %r = fadd half %xf, %yf
17  ret half %r
18}
19
20define half @test_ui_ui_i8_add_fail_overflow(i8 noundef %x_in, i8 noundef %y_in) {
21; CHECK-LABEL: @test_ui_ui_i8_add_fail_overflow(
22; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 127
23; CHECK-NEXT:    [[Y:%.*]] = and i8 [[Y_IN:%.*]], -127
24; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
25; CHECK-NEXT:    [[YF:%.*]] = uitofp i8 [[Y]] to half
26; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], [[YF]]
27; CHECK-NEXT:    ret half [[R]]
28;
29  %x = and i8 %x_in, 127
30  %y = and i8 %y_in, 129
31  %xf = uitofp i8 %x to half
32  %yf = uitofp i8 %y to half
33  %r = fadd half %xf, %yf
34  ret half %r
35}
36
37define half @test_ui_ui_i8_add_C(i8 noundef %x_in) {
38; CHECK-LABEL: @test_ui_ui_i8_add_C(
39; CHECK-NEXT:    [[TMP1:%.*]] = or i8 [[X_IN:%.*]], -128
40; CHECK-NEXT:    [[R:%.*]] = uitofp i8 [[TMP1]] to half
41; CHECK-NEXT:    ret half [[R]]
42;
43  %x = and i8 %x_in, 127
44  %xf = uitofp i8 %x to half
45  %r = fadd half %xf, 128.0
46  ret half %r
47}
48
49define half @test_ui_ui_i8_add_C_fail_no_repr(i8 noundef %x_in) {
50; CHECK-LABEL: @test_ui_ui_i8_add_C_fail_no_repr(
51; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 127
52; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
53; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], 0xH57F8
54; CHECK-NEXT:    ret half [[R]]
55;
56  %x = and i8 %x_in, 127
57  %xf = uitofp i8 %x to half
58  %r = fadd half %xf, 127.5
59  ret half %r
60}
61
62define half @test_ui_ui_i8_add_C_fail_overflow(i8 noundef %x_in) {
63; CHECK-LABEL: @test_ui_ui_i8_add_C_fail_overflow(
64; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 127
65; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
66; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], 0xH5808
67; CHECK-NEXT:    ret half [[R]]
68;
69  %x = and i8 %x_in, 127
70  %xf = uitofp i8 %x to half
71  %r = fadd half %xf, 129.0
72  ret half %r
73}
74
75define half @test_si_si_i8_add(i8 noundef %x_in, i8 noundef %y_in) {
76; CHECK-LABEL: @test_si_si_i8_add(
77; CHECK-NEXT:    [[X:%.*]] = or i8 [[X_IN:%.*]], -64
78; CHECK-NEXT:    [[Y:%.*]] = or i8 [[Y_IN:%.*]], -64
79; CHECK-NEXT:    [[TMP1:%.*]] = add nsw i8 [[X]], [[Y]]
80; CHECK-NEXT:    [[R:%.*]] = sitofp i8 [[TMP1]] to half
81; CHECK-NEXT:    ret half [[R]]
82;
83  %x = or i8 %x_in, -64
84  %y = or i8 %y_in, -64
85  %xf = sitofp i8 %x to half
86  %yf = sitofp i8 %y to half
87  %r = fadd half %xf, %yf
88  ret half %r
89}
90
91define half @test_si_si_i8_add_fail_overflow(i8 noundef %x_in, i8 noundef %y_in) {
92; CHECK-LABEL: @test_si_si_i8_add_fail_overflow(
93; CHECK-NEXT:    [[X:%.*]] = or i8 [[X_IN:%.*]], -64
94; CHECK-NEXT:    [[Y:%.*]] = or i8 [[Y_IN:%.*]], -65
95; CHECK-NEXT:    [[XF:%.*]] = sitofp i8 [[X]] to half
96; CHECK-NEXT:    [[YF:%.*]] = sitofp i8 [[Y]] to half
97; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], [[YF]]
98; CHECK-NEXT:    ret half [[R]]
99;
100  %x = or i8 %x_in, -64
101  %y = or i8 %y_in, -65
102  %xf = sitofp i8 %x to half
103  %yf = sitofp i8 %y to half
104  %r = fadd half %xf, %yf
105  ret half %r
106}
107
108define half @test_ui_si_i8_add(i8 noundef %x_in, i8 noundef %y_in) {
109; CHECK-LABEL: @test_ui_si_i8_add(
110; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 63
111; CHECK-NEXT:    [[Y:%.*]] = and i8 [[Y_IN:%.*]], 63
112; CHECK-NEXT:    [[TMP1:%.*]] = add nuw nsw i8 [[X]], [[Y]]
113; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i8 [[TMP1]] to half
114; CHECK-NEXT:    ret half [[R]]
115;
116  %x = and i8 %x_in, 63
117  %y = and i8 %y_in, 63
118  %xf = sitofp i8 %x to half
119  %yf = uitofp i8 %y to half
120  %r = fadd half %xf, %yf
121  ret half %r
122}
123
124define half @test_ui_si_i8_add_overflow(i8 noundef %x_in, i8 noundef %y_in) {
125; CHECK-LABEL: @test_ui_si_i8_add_overflow(
126; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 63
127; CHECK-NEXT:    [[Y:%.*]] = and i8 [[Y_IN:%.*]], 65
128; CHECK-NEXT:    [[TMP1:%.*]] = add nuw i8 [[X]], [[Y]]
129; CHECK-NEXT:    [[R:%.*]] = uitofp i8 [[TMP1]] to half
130; CHECK-NEXT:    ret half [[R]]
131;
132  %x = and i8 %x_in, 63
133  %y = and i8 %y_in, 65
134  %xf = sitofp i8 %x to half
135  %yf = uitofp i8 %y to half
136  %r = fadd half %xf, %yf
137  ret half %r
138}
139
140define half @test_ui_ui_i8_sub_C(i8 noundef %x_in) {
141; CHECK-LABEL: @test_ui_ui_i8_sub_C(
142; CHECK-NEXT:    [[TMP1:%.*]] = and i8 [[X_IN:%.*]], 127
143; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i8 [[TMP1]] to half
144; CHECK-NEXT:    ret half [[R]]
145;
146  %x = or i8 %x_in, 128
147  %xf = uitofp i8 %x to half
148  %r = fsub half %xf, 128.0
149  ret half %r
150}
151
152define half @test_ui_ui_i8_sub_C_fail_overflow(i8 noundef %x_in) {
153; CHECK-LABEL: @test_ui_ui_i8_sub_C_fail_overflow(
154; CHECK-NEXT:    [[TMP1:%.*]] = or i8 [[X_IN:%.*]], -128
155; CHECK-NEXT:    [[R:%.*]] = sitofp i8 [[TMP1]] to half
156; CHECK-NEXT:    ret half [[R]]
157;
158  %x = and i8 %x_in, 127
159  %xf = uitofp i8 %x to half
160  %r = fsub half %xf, 128.0
161  ret half %r
162}
163
164define half @test_si_si_i8_sub(i8 noundef %x_in, i8 noundef %y_in) {
165; CHECK-LABEL: @test_si_si_i8_sub(
166; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 63
167; CHECK-NEXT:    [[Y:%.*]] = or i8 [[Y_IN:%.*]], -64
168; CHECK-NEXT:    [[TMP1:%.*]] = sub nsw i8 [[X]], [[Y]]
169; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i8 [[TMP1]] to half
170; CHECK-NEXT:    ret half [[R]]
171;
172  %x = and i8 %x_in, 63
173  %y = or i8 %y_in, -64
174  %xf = sitofp i8 %x to half
175  %yf = sitofp i8 %y to half
176  %r = fsub half %xf, %yf
177  ret half %r
178}
179
180define half @test_si_si_i8_sub_fail_overflow(i8 noundef %x_in, i8 noundef %y_in) {
181; CHECK-LABEL: @test_si_si_i8_sub_fail_overflow(
182; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 63
183; CHECK-NEXT:    [[Y:%.*]] = or i8 [[Y_IN:%.*]], -65
184; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
185; CHECK-NEXT:    [[YF:%.*]] = sitofp i8 [[Y]] to half
186; CHECK-NEXT:    [[R:%.*]] = fsub half [[XF]], [[YF]]
187; CHECK-NEXT:    ret half [[R]]
188;
189  %x = and i8 %x_in, 63
190  %y = or i8 %y_in, -65
191  %xf = sitofp i8 %x to half
192  %yf = sitofp i8 %y to half
193  %r = fsub half %xf, %yf
194  ret half %r
195}
196
197define half @test_si_si_i8_sub_C(i8 noundef %x_in) {
198; CHECK-LABEL: @test_si_si_i8_sub_C(
199; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 63
200; CHECK-NEXT:    [[TMP1:%.*]] = or disjoint i8 [[X]], 64
201; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i8 [[TMP1]] to half
202; CHECK-NEXT:    ret half [[R]]
203;
204  %x = and i8 %x_in, 63
205  %xf = sitofp i8 %x to half
206  %r = fsub half %xf, -64.0
207  ret half %r
208}
209
210define half @test_si_si_i8_sub_C_fail_overflow(i8 noundef %x_in) {
211; CHECK-LABEL: @test_si_si_i8_sub_C_fail_overflow(
212; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 65
213; CHECK-NEXT:    [[TMP1:%.*]] = add nuw i8 [[X]], 64
214; CHECK-NEXT:    [[R:%.*]] = uitofp i8 [[TMP1]] to half
215; CHECK-NEXT:    ret half [[R]]
216;
217  %x = and i8 %x_in, 65
218  %xf = sitofp i8 %x to half
219  %r = fsub half %xf, -64.0
220  ret half %r
221}
222
223define half @test_ui_si_i8_sub(i8 noundef %x_in, i8 noundef %y_in) {
224; CHECK-LABEL: @test_ui_si_i8_sub(
225; CHECK-NEXT:    [[X:%.*]] = or i8 [[X_IN:%.*]], 64
226; CHECK-NEXT:    [[Y:%.*]] = and i8 [[Y_IN:%.*]], 63
227; CHECK-NEXT:    [[TMP1:%.*]] = sub nuw nsw i8 [[X]], [[Y]]
228; CHECK-NEXT:    [[R:%.*]] = sitofp i8 [[TMP1]] to half
229; CHECK-NEXT:    ret half [[R]]
230;
231  %x = or i8 %x_in, 64
232  %y = and i8 %y_in, 63
233  %xf = sitofp i8 %x to half
234  %yf = uitofp i8 %y to half
235  %r = fsub half %xf, %yf
236  ret half %r
237}
238
239define half @test_ui_si_i8_sub_fail_maybe_sign(i8 noundef %x_in, i8 noundef %y_in) {
240; CHECK-LABEL: @test_ui_si_i8_sub_fail_maybe_sign(
241; CHECK-NEXT:    [[X:%.*]] = or i8 [[X_IN:%.*]], 64
242; CHECK-NEXT:    [[Y:%.*]] = and i8 [[Y_IN:%.*]], 63
243; CHECK-NEXT:    [[TMP1:%.*]] = sub nuw nsw i8 [[X]], [[Y]]
244; CHECK-NEXT:    [[R:%.*]] = uitofp i8 [[TMP1]] to half
245; CHECK-NEXT:    ret half [[R]]
246;
247  %x = or i8 %x_in, 64
248  %y = and i8 %y_in, 63
249  %xf = uitofp i8 %x to half
250  %yf = sitofp i8 %y to half
251  %r = fsub half %xf, %yf
252  ret half %r
253}
254
255define half @test_ui_ui_i8_mul(i8 noundef %x_in, i8 noundef %y_in) {
256; CHECK-LABEL: @test_ui_ui_i8_mul(
257; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 15
258; CHECK-NEXT:    [[Y:%.*]] = and i8 [[Y_IN:%.*]], 15
259; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw i8 [[X]], [[Y]]
260; CHECK-NEXT:    [[R:%.*]] = uitofp i8 [[TMP1]] to half
261; CHECK-NEXT:    ret half [[R]]
262;
263  %x = and i8 %x_in, 15
264  %y = and i8 %y_in, 15
265  %xf = uitofp i8 %x to half
266  %yf = uitofp i8 %y to half
267  %r = fmul half %xf, %yf
268  ret half %r
269}
270
271define half @test_ui_ui_i8_mul_C(i8 noundef %x_in) {
272; CHECK-LABEL: @test_ui_ui_i8_mul_C(
273; CHECK-NEXT:    [[X:%.*]] = shl i8 [[X_IN:%.*]], 4
274; CHECK-NEXT:    [[R:%.*]] = uitofp i8 [[X]] to half
275; CHECK-NEXT:    ret half [[R]]
276;
277  %x = and i8 %x_in, 15
278  %xf = uitofp i8 %x to half
279  %r = fmul half %xf, 16.0
280  ret half %r
281}
282
283define half @test_ui_ui_i8_mul_C_fail_overlow(i8 noundef %x_in) {
284; CHECK-LABEL: @test_ui_ui_i8_mul_C_fail_overlow(
285; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 14
286; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
287; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], 0xH4CC0
288; CHECK-NEXT:    ret half [[R]]
289;
290  %x = and i8 %x_in, 14
291  %xf = uitofp i8 %x to half
292  %r = fmul half %xf, 19.0
293  ret half %r
294}
295
296define half @test_si_si_i8_mul(i8 noundef %x_in, i8 noundef %y_in) {
297; CHECK-LABEL: @test_si_si_i8_mul(
298; CHECK-NEXT:    [[XX:%.*]] = and i8 [[X_IN:%.*]], 6
299; CHECK-NEXT:    [[X:%.*]] = or disjoint i8 [[XX]], 1
300; CHECK-NEXT:    [[Y:%.*]] = or i8 [[Y_IN:%.*]], -8
301; CHECK-NEXT:    [[TMP1:%.*]] = mul nsw i8 [[X]], [[Y]]
302; CHECK-NEXT:    [[R:%.*]] = sitofp i8 [[TMP1]] to half
303; CHECK-NEXT:    ret half [[R]]
304;
305  %xx = and i8 %x_in, 6
306  %x = add nsw nuw i8 %xx, 1
307  %y = or i8 %y_in, -8
308  %xf = sitofp i8 %x to half
309  %yf = sitofp i8 %y to half
310  %r = fmul half %xf, %yf
311  ret half %r
312}
313
314define half @test_si_si_i8_mul_fail_maybe_zero(i8 noundef %x_in, i8 noundef %y_in) {
315; CHECK-LABEL: @test_si_si_i8_mul_fail_maybe_zero(
316; CHECK-NEXT:    [[X:%.*]] = and i8 [[X_IN:%.*]], 7
317; CHECK-NEXT:    [[Y:%.*]] = or i8 [[Y_IN:%.*]], -8
318; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
319; CHECK-NEXT:    [[YF:%.*]] = sitofp i8 [[Y]] to half
320; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], [[YF]]
321; CHECK-NEXT:    ret half [[R]]
322;
323  %x = and i8 %x_in, 7
324  %y = or i8 %y_in, -8
325  %xf = sitofp i8 %x to half
326  %yf = sitofp i8 %y to half
327  %r = fmul half %xf, %yf
328  ret half %r
329}
330
331define half @test_si_si_i8_mul_C_fail_no_repr(i8 noundef %x_in) {
332; CHECK-LABEL: @test_si_si_i8_mul_C_fail_no_repr(
333; CHECK-NEXT:    [[XX:%.*]] = and i8 [[X_IN:%.*]], 6
334; CHECK-NEXT:    [[X:%.*]] = or disjoint i8 [[XX]], 1
335; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
336; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], 0xHC780
337; CHECK-NEXT:    ret half [[R]]
338;
339  %xx = and i8 %x_in, 6
340  %x = add nsw nuw i8 %xx, 1
341  %xf = sitofp i8 %x to half
342  %r = fmul half %xf, -7.5
343  ret half %r
344}
345
346define half @test_si_si_i8_mul_C_fail_overflow(i8 noundef %x_in) {
347; CHECK-LABEL: @test_si_si_i8_mul_C_fail_overflow(
348; CHECK-NEXT:    [[XX:%.*]] = and i8 [[X_IN:%.*]], 6
349; CHECK-NEXT:    [[X:%.*]] = or disjoint i8 [[XX]], 1
350; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
351; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], 0xHCCC0
352; CHECK-NEXT:    ret half [[R]]
353;
354  %xx = and i8 %x_in, 6
355  %x = add nsw nuw i8 %xx, 1
356  %xf = sitofp i8 %x to half
357  %r = fmul half %xf, -19.0
358  ret half %r
359}
360
361define half @test_ui_si_i8_mul(i8 noundef %x_in, i8 noundef %y_in) {
362; CHECK-LABEL: @test_ui_si_i8_mul(
363; CHECK-NEXT:    [[XX:%.*]] = and i8 [[X_IN:%.*]], 6
364; CHECK-NEXT:    [[X:%.*]] = or disjoint i8 [[XX]], 1
365; CHECK-NEXT:    [[YY:%.*]] = and i8 [[Y_IN:%.*]], 7
366; CHECK-NEXT:    [[Y:%.*]] = add nuw nsw i8 [[YY]], 1
367; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw nsw i8 [[X]], [[Y]]
368; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i8 [[TMP1]] to half
369; CHECK-NEXT:    ret half [[R]]
370;
371  %xx = and i8 %x_in, 6
372  %x = add i8 %xx, 1
373  %yy = and i8 %y_in, 7
374  %y = add i8 %yy, 1
375  %xf = sitofp i8 %x to half
376  %yf = uitofp i8 %y to half
377  %r = fmul half %xf, %yf
378  ret half %r
379}
380
381define half @test_ui_si_i8_mul_fail_maybe_zero(i8 noundef %x_in, i8 noundef %y_in) {
382; CHECK-LABEL: @test_ui_si_i8_mul_fail_maybe_zero(
383; CHECK-NEXT:    [[XX:%.*]] = and i8 [[X_IN:%.*]], 7
384; CHECK-NEXT:    [[X:%.*]] = add nuw nsw i8 [[XX]], 1
385; CHECK-NEXT:    [[Y:%.*]] = and i8 [[Y_IN:%.*]], 7
386; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw nsw i8 [[X]], [[Y]]
387; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i8 [[TMP1]] to half
388; CHECK-NEXT:    ret half [[R]]
389;
390  %xx = and i8 %x_in, 7
391  %x = add i8 %xx, 1
392  %y = and i8 %y_in, 7
393  %xf = sitofp i8 %x to half
394  %yf = uitofp i8 %y to half
395  %r = fmul half %xf, %yf
396  ret half %r
397}
398
399define half @test_ui_si_i8_mul_fail_signed(i8 noundef %x_in, i8 noundef %y_in) {
400; CHECK-LABEL: @test_ui_si_i8_mul_fail_signed(
401; CHECK-NEXT:    [[XX:%.*]] = and i8 [[X_IN:%.*]], 7
402; CHECK-NEXT:    [[X:%.*]] = add nuw nsw i8 [[XX]], 1
403; CHECK-NEXT:    [[Y:%.*]] = or i8 [[Y_IN:%.*]], -4
404; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i8 [[X]] to half
405; CHECK-NEXT:    [[YF:%.*]] = uitofp i8 [[Y]] to half
406; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], [[YF]]
407; CHECK-NEXT:    ret half [[R]]
408;
409  %xx = and i8 %x_in, 7
410  %x = add i8 %xx, 1
411  %y = or i8 %y_in, -4
412  %xf = sitofp i8 %x to half
413  %yf = uitofp i8 %y to half
414  %r = fmul half %xf, %yf
415  ret half %r
416}
417
418define half @test_ui_ui_i16_add(i16 noundef %x_in, i16 noundef %y_in) {
419; CHECK-LABEL: @test_ui_ui_i16_add(
420; CHECK-NEXT:    [[X:%.*]] = and i16 [[X_IN:%.*]], 2047
421; CHECK-NEXT:    [[Y:%.*]] = and i16 [[Y_IN:%.*]], 2047
422; CHECK-NEXT:    [[TMP1:%.*]] = add nuw nsw i16 [[X]], [[Y]]
423; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i16 [[TMP1]] to half
424; CHECK-NEXT:    ret half [[R]]
425;
426  %x = and i16 %x_in, 2047
427  %y = and i16 %y_in, 2047
428  %xf = uitofp i16 %x to half
429  %yf = uitofp i16 %y to half
430  %r = fadd half %xf, %yf
431  ret half %r
432}
433
434define half @test_ui_ui_i16_add_fail_not_promotable(i16 noundef %x_in, i16 noundef %y_in) {
435; CHECK-LABEL: @test_ui_ui_i16_add_fail_not_promotable(
436; CHECK-NEXT:    [[X:%.*]] = and i16 [[X_IN:%.*]], 2049
437; CHECK-NEXT:    [[Y:%.*]] = and i16 [[Y_IN:%.*]], 2047
438; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i16 [[X]] to half
439; CHECK-NEXT:    [[YF:%.*]] = uitofp nneg i16 [[Y]] to half
440; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], [[YF]]
441; CHECK-NEXT:    ret half [[R]]
442;
443  %x = and i16 %x_in, 2049
444  %y = and i16 %y_in, 2047
445  %xf = uitofp i16 %x to half
446  %yf = uitofp i16 %y to half
447  %r = fadd half %xf, %yf
448  ret half %r
449}
450
451define half @test_ui_ui_i16_add_C(i16 noundef %x_in) {
452; CHECK-LABEL: @test_ui_ui_i16_add_C(
453; CHECK-NEXT:    [[TMP1:%.*]] = or i16 [[X_IN:%.*]], -2048
454; CHECK-NEXT:    [[R:%.*]] = uitofp i16 [[TMP1]] to half
455; CHECK-NEXT:    ret half [[R]]
456;
457  %x = and i16 %x_in, 2047
458  %xf = uitofp i16 %x to half
459  %r = fadd half %xf, 63488.0
460  ret half %r
461}
462
463define half @test_ui_ui_i16_add_C_fail_overflow(i16 noundef %x_in) {
464; CHECK-LABEL: @test_ui_ui_i16_add_C_fail_overflow(
465; CHECK-NEXT:    [[X:%.*]] = and i16 [[X_IN:%.*]], 2047
466; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i16 [[X]] to half
467; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], 0xH7BD0
468; CHECK-NEXT:    ret half [[R]]
469;
470  %x = and i16 %x_in, 2047
471  %xf = uitofp i16 %x to half
472  %r = fadd half %xf, 64000.0
473  ret half %r
474}
475
476define half @test_si_si_i16_add(i16 noundef %x_in, i16 noundef %y_in) {
477; CHECK-LABEL: @test_si_si_i16_add(
478; CHECK-NEXT:    [[X:%.*]] = or i16 [[X_IN:%.*]], -2048
479; CHECK-NEXT:    [[Y:%.*]] = or i16 [[Y_IN:%.*]], -2048
480; CHECK-NEXT:    [[TMP1:%.*]] = add nsw i16 [[X]], [[Y]]
481; CHECK-NEXT:    [[R:%.*]] = sitofp i16 [[TMP1]] to half
482; CHECK-NEXT:    ret half [[R]]
483;
484  %x = or i16 %x_in, -2048
485  %y = or i16 %y_in, -2048
486  %xf = sitofp i16 %x to half
487  %yf = sitofp i16 %y to half
488  %r = fadd half %xf, %yf
489  ret half %r
490}
491
492define half @test_si_si_i16_add_fail_no_promotion(i16 noundef %x_in, i16 noundef %y_in) {
493; CHECK-LABEL: @test_si_si_i16_add_fail_no_promotion(
494; CHECK-NEXT:    [[XX:%.*]] = or i16 [[X_IN:%.*]], -2048
495; CHECK-NEXT:    [[X:%.*]] = add nsw i16 [[XX]], -1
496; CHECK-NEXT:    [[Y:%.*]] = or i16 [[Y_IN:%.*]], -2048
497; CHECK-NEXT:    [[XF:%.*]] = sitofp i16 [[X]] to half
498; CHECK-NEXT:    [[YF:%.*]] = sitofp i16 [[Y]] to half
499; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], [[YF]]
500; CHECK-NEXT:    ret half [[R]]
501;
502  %xx = or i16 %x_in, -2048
503  %x = sub i16 %xx, 1
504  %y = or i16 %y_in, -2048
505  %xf = sitofp i16 %x to half
506  %yf = sitofp i16 %y to half
507  %r = fadd half %xf, %yf
508  ret half %r
509}
510
511define half @test_si_si_i16_add_C_overflow(i16 noundef %x_in) {
512; CHECK-LABEL: @test_si_si_i16_add_C_overflow(
513; CHECK-NEXT:    [[X:%.*]] = or i16 [[X_IN:%.*]], -2048
514; CHECK-NEXT:    [[XF:%.*]] = sitofp i16 [[X]] to half
515; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], 0xH7840
516; CHECK-NEXT:    ret half [[R]]
517;
518  %x = or i16 %x_in, -2048
519  %xf = sitofp i16 %x to half
520  %r = fadd half %xf, 0xH7840
521  ret half %r
522}
523
524define half @test_si_si_i16_sub(i16 noundef %x_in, i16 noundef %y_in) {
525; CHECK-LABEL: @test_si_si_i16_sub(
526; CHECK-NEXT:    [[X:%.*]] = or i16 [[X_IN:%.*]], -2048
527; CHECK-NEXT:    [[Y:%.*]] = and i16 [[Y_IN:%.*]], 2047
528; CHECK-NEXT:    [[TMP1:%.*]] = sub nuw nsw i16 [[X]], [[Y]]
529; CHECK-NEXT:    [[R:%.*]] = sitofp i16 [[TMP1]] to half
530; CHECK-NEXT:    ret half [[R]]
531;
532  %x = or i16 %x_in, -2048
533  %y = and i16 %y_in, 2047
534  %xf = sitofp i16 %x to half
535  %yf = sitofp i16 %y to half
536  %r = fsub half %xf, %yf
537  ret half %r
538}
539
540define half @test_si_si_i16_sub_fail_no_promotion(i16 noundef %x_in, i16 noundef %y_in) {
541; CHECK-LABEL: @test_si_si_i16_sub_fail_no_promotion(
542; CHECK-NEXT:    [[X:%.*]] = and i16 [[X_IN:%.*]], 2047
543; CHECK-NEXT:    [[Y:%.*]] = or i16 [[Y_IN:%.*]], -2049
544; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i16 [[X]] to half
545; CHECK-NEXT:    [[YF:%.*]] = sitofp i16 [[Y]] to half
546; CHECK-NEXT:    [[R:%.*]] = fsub half [[XF]], [[YF]]
547; CHECK-NEXT:    ret half [[R]]
548;
549  %x = and i16 %x_in, 2047
550  %y = or i16 %y_in, -2049
551  %xf = sitofp i16 %x to half
552  %yf = sitofp i16 %y to half
553  %r = fsub half %xf, %yf
554  ret half %r
555}
556
557define half @test_ui_si_i16_sub(i16 noundef %x_in, i16 noundef %y_in) {
558; CHECK-LABEL: @test_ui_si_i16_sub(
559; CHECK-NEXT:    [[X:%.*]] = and i16 [[X_IN:%.*]], 2047
560; CHECK-NEXT:    [[Y:%.*]] = and i16 [[Y_IN:%.*]], 2047
561; CHECK-NEXT:    [[TMP1:%.*]] = sub nsw i16 [[X]], [[Y]]
562; CHECK-NEXT:    [[R:%.*]] = sitofp i16 [[TMP1]] to half
563; CHECK-NEXT:    ret half [[R]]
564;
565  %x = and i16 %x_in, 2047
566  %y = and i16 %y_in, 2047
567  %xf = uitofp i16 %x to half
568  %yf = sitofp i16 %y to half
569  %r = fsub half %xf, %yf
570  ret half %r
571}
572
573define half @test_ui_si_i16_sub_fail_maybe_signed(i16 noundef %x_in, i16 noundef %y_in) {
574; CHECK-LABEL: @test_ui_si_i16_sub_fail_maybe_signed(
575; CHECK-NEXT:    [[X:%.*]] = or i16 [[X_IN:%.*]], -2048
576; CHECK-NEXT:    [[Y:%.*]] = and i16 [[Y_IN:%.*]], 2047
577; CHECK-NEXT:    [[XF:%.*]] = uitofp i16 [[X]] to half
578; CHECK-NEXT:    [[YF:%.*]] = uitofp nneg i16 [[Y]] to half
579; CHECK-NEXT:    [[R:%.*]] = fsub half [[XF]], [[YF]]
580; CHECK-NEXT:    ret half [[R]]
581;
582  %x = or i16 %x_in, -2048
583  %y = and i16 %y_in, 2047
584  %xf = uitofp i16 %x to half
585  %yf = sitofp i16 %y to half
586  %r = fsub half %xf, %yf
587  ret half %r
588}
589
590define half @test_ui_ui_i16_mul(i16 noundef %x_in, i16 noundef %y_in) {
591; CHECK-LABEL: @test_ui_ui_i16_mul(
592; CHECK-NEXT:    [[X:%.*]] = and i16 [[X_IN:%.*]], 255
593; CHECK-NEXT:    [[Y:%.*]] = and i16 [[Y_IN:%.*]], 255
594; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw i16 [[X]], [[Y]]
595; CHECK-NEXT:    [[R:%.*]] = uitofp i16 [[TMP1]] to half
596; CHECK-NEXT:    ret half [[R]]
597;
598  %x = and i16 %x_in, 255
599  %y = and i16 %y_in, 255
600  %xf = uitofp i16 %x to half
601  %yf = uitofp i16 %y to half
602  %r = fmul half %xf, %yf
603  ret half %r
604}
605
606define half @test_ui_ui_i16_mul_fail_no_promotion(i16 noundef %x_in, i16 noundef %y_in) {
607; CHECK-LABEL: @test_ui_ui_i16_mul_fail_no_promotion(
608; CHECK-NEXT:    [[X:%.*]] = and i16 [[X_IN:%.*]], 4095
609; CHECK-NEXT:    [[Y:%.*]] = and i16 [[Y_IN:%.*]], 3
610; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i16 [[X]] to half
611; CHECK-NEXT:    [[YF:%.*]] = uitofp nneg i16 [[Y]] to half
612; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], [[YF]]
613; CHECK-NEXT:    ret half [[R]]
614;
615  %x = and i16 %x_in, 4095
616  %y = and i16 %y_in, 3
617  %xf = uitofp i16 %x to half
618  %yf = uitofp i16 %y to half
619  %r = fmul half %xf, %yf
620  ret half %r
621}
622
623define half @test_si_si_i16_mul(i16 noundef %x_in, i16 noundef %y_in) {
624; CHECK-LABEL: @test_si_si_i16_mul(
625; CHECK-NEXT:    [[XX:%.*]] = and i16 [[X_IN:%.*]], 126
626; CHECK-NEXT:    [[X:%.*]] = or disjoint i16 [[XX]], 1
627; CHECK-NEXT:    [[Y:%.*]] = or i16 [[Y_IN:%.*]], -255
628; CHECK-NEXT:    [[TMP1:%.*]] = mul nsw i16 [[X]], [[Y]]
629; CHECK-NEXT:    [[R:%.*]] = sitofp i16 [[TMP1]] to half
630; CHECK-NEXT:    ret half [[R]]
631;
632  %xx = and i16 %x_in, 126
633  %x = add nsw nuw i16 %xx, 1
634  %y = or i16 %y_in, -255
635  %xf = sitofp i16 %x to half
636  %yf = sitofp i16 %y to half
637  %r = fmul half %xf, %yf
638  ret half %r
639}
640
641define half @test_si_si_i16_mul_fail_overflow(i16 noundef %x_in, i16 noundef %y_in) {
642; CHECK-LABEL: @test_si_si_i16_mul_fail_overflow(
643; CHECK-NEXT:    [[XX:%.*]] = and i16 [[X_IN:%.*]], 126
644; CHECK-NEXT:    [[X:%.*]] = or disjoint i16 [[XX]], 1
645; CHECK-NEXT:    [[Y:%.*]] = or i16 [[Y_IN:%.*]], -257
646; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i16 [[X]] to half
647; CHECK-NEXT:    [[YF:%.*]] = sitofp i16 [[Y]] to half
648; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], [[YF]]
649; CHECK-NEXT:    ret half [[R]]
650;
651  %xx = and i16 %x_in, 126
652  %x = add nsw nuw i16 %xx, 1
653  %y = or i16 %y_in, -257
654  %xf = sitofp i16 %x to half
655  %yf = sitofp i16 %y to half
656  %r = fmul half %xf, %yf
657  ret half %r
658}
659
660define half @test_si_si_i16_mul_C_fail_overflow(i16 noundef %x_in) {
661; CHECK-LABEL: @test_si_si_i16_mul_C_fail_overflow(
662; CHECK-NEXT:    [[X:%.*]] = or i16 [[X_IN:%.*]], -129
663; CHECK-NEXT:    [[XF:%.*]] = sitofp i16 [[X]] to half
664; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], 0xH5800
665; CHECK-NEXT:    ret half [[R]]
666;
667  %x = or i16 %x_in, -129
668  %xf = sitofp i16 %x to half
669  %r = fmul half %xf, 128.0
670  ret half %r
671}
672
673define half @test_si_si_i16_mul_C_fail_no_promotion(i16 noundef %x_in) {
674; CHECK-LABEL: @test_si_si_i16_mul_C_fail_no_promotion(
675; CHECK-NEXT:    [[X:%.*]] = or i16 [[X_IN:%.*]], -4097
676; CHECK-NEXT:    [[XF:%.*]] = sitofp i16 [[X]] to half
677; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], 0xH4500
678; CHECK-NEXT:    ret half [[R]]
679;
680  %x = or i16 %x_in, -4097
681  %xf = sitofp i16 %x to half
682  %r = fmul half %xf, 5.0
683  ret half %r
684}
685
686define half @test_ui_si_i16_mul(i16 noundef %x_in, i16 noundef %y_in) {
687; CHECK-LABEL: @test_ui_si_i16_mul(
688; CHECK-NEXT:    [[XX:%.*]] = and i16 [[X_IN:%.*]], 126
689; CHECK-NEXT:    [[X:%.*]] = or disjoint i16 [[XX]], 1
690; CHECK-NEXT:    [[YY:%.*]] = and i16 [[Y_IN:%.*]], 126
691; CHECK-NEXT:    [[Y:%.*]] = or disjoint i16 [[YY]], 1
692; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw nsw i16 [[X]], [[Y]]
693; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i16 [[TMP1]] to half
694; CHECK-NEXT:    ret half [[R]]
695;
696  %xx = and i16 %x_in, 126
697  %x = add i16 %xx, 1
698  %yy = and i16 %y_in, 126
699  %y = add i16 %yy, 1
700  %xf = sitofp i16 %x to half
701  %yf = uitofp i16 %y to half
702  %r = fmul half %xf, %yf
703  ret half %r
704}
705
706define half @test_ui_ui_i12_add(i12 noundef %x_in, i12 noundef %y_in) {
707; CHECK-LABEL: @test_ui_ui_i12_add(
708; CHECK-NEXT:    [[X:%.*]] = and i12 [[X_IN:%.*]], 2047
709; CHECK-NEXT:    [[Y:%.*]] = and i12 [[Y_IN:%.*]], 2047
710; CHECK-NEXT:    [[TMP1:%.*]] = add nuw i12 [[X]], [[Y]]
711; CHECK-NEXT:    [[R:%.*]] = uitofp i12 [[TMP1]] to half
712; CHECK-NEXT:    ret half [[R]]
713;
714  %x = and i12 %x_in, 2047
715  %y = and i12 %y_in, 2047
716  %xf = uitofp i12 %x to half
717  %yf = uitofp i12 %y to half
718  %r = fadd half %xf, %yf
719  ret half %r
720}
721
722define half @test_ui_ui_i12_add_fail_overflow(i12 noundef %x_in, i12 noundef %y_in) {
723; CHECK-LABEL: @test_ui_ui_i12_add_fail_overflow(
724; CHECK-NEXT:    [[X:%.*]] = and i12 [[X_IN:%.*]], 2047
725; CHECK-NEXT:    [[Y:%.*]] = and i12 [[Y_IN:%.*]], -2047
726; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i12 [[X]] to half
727; CHECK-NEXT:    [[YF:%.*]] = uitofp i12 [[Y]] to half
728; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], [[YF]]
729; CHECK-NEXT:    ret half [[R]]
730;
731  %x = and i12 %x_in, 2047
732  %y = and i12 %y_in, 2049
733  %xf = uitofp i12 %x to half
734  %yf = uitofp i12 %y to half
735  %r = fadd half %xf, %yf
736  ret half %r
737}
738
739
740define half @test_si_si_i12_add(i12 noundef %x_in, i12 noundef %y_in) {
741; CHECK-LABEL: @test_si_si_i12_add(
742; CHECK-NEXT:    [[X:%.*]] = or i12 [[X_IN:%.*]], -1024
743; CHECK-NEXT:    [[Y:%.*]] = or i12 [[Y_IN:%.*]], -1024
744; CHECK-NEXT:    [[TMP1:%.*]] = add nsw i12 [[X]], [[Y]]
745; CHECK-NEXT:    [[R:%.*]] = sitofp i12 [[TMP1]] to half
746; CHECK-NEXT:    ret half [[R]]
747;
748  %x = or i12 %x_in, -1024
749  %y = or i12 %y_in, -1024
750  %xf = sitofp i12 %x to half
751  %yf = sitofp i12 %y to half
752  %r = fadd half %xf, %yf
753  ret half %r
754}
755
756define half @test_si_si_i12_add_fail_overflow(i12 noundef %x_in, i12 noundef %y_in) {
757; CHECK-LABEL: @test_si_si_i12_add_fail_overflow(
758; CHECK-NEXT:    [[X:%.*]] = or i12 [[X_IN:%.*]], -1025
759; CHECK-NEXT:    [[Y:%.*]] = or i12 [[Y_IN:%.*]], -1025
760; CHECK-NEXT:    [[XF:%.*]] = sitofp i12 [[X]] to half
761; CHECK-NEXT:    [[YF:%.*]] = sitofp i12 [[Y]] to half
762; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], [[YF]]
763; CHECK-NEXT:    ret half [[R]]
764;
765  %x = or i12 %x_in, -1025
766  %y = or i12 %y_in, -1025
767  %xf = sitofp i12 %x to half
768  %yf = sitofp i12 %y to half
769  %r = fadd half %xf, %yf
770  ret half %r
771}
772
773define half @test_si_si_i12_add_C_fail_overflow(i12 noundef %x_in) {
774; CHECK-LABEL: @test_si_si_i12_add_C_fail_overflow(
775; CHECK-NEXT:    [[X:%.*]] = or i12 [[X_IN:%.*]], -2048
776; CHECK-NEXT:    [[XF:%.*]] = sitofp i12 [[X]] to half
777; CHECK-NEXT:    [[R:%.*]] = fadd half [[XF]], 0xHBC00
778; CHECK-NEXT:    ret half [[R]]
779;
780  %x = or i12 %x_in, -2048
781  %xf = sitofp i12 %x to half
782  %r = fadd half %xf, -1.0
783  ret half %r
784}
785
786define half @test_ui_ui_i12_sub(i12 noundef %x_in, i12 noundef %y_in) {
787; CHECK-LABEL: @test_ui_ui_i12_sub(
788; CHECK-NEXT:    [[X:%.*]] = and i12 [[X_IN:%.*]], 1023
789; CHECK-NEXT:    [[Y:%.*]] = and i12 [[Y_IN:%.*]], 1023
790; CHECK-NEXT:    [[TMP1:%.*]] = sub nsw i12 [[X]], [[Y]]
791; CHECK-NEXT:    [[R:%.*]] = sitofp i12 [[TMP1]] to half
792; CHECK-NEXT:    ret half [[R]]
793;
794  %x = and i12 %x_in, 1023
795  %y = and i12 %y_in, 1023
796  %xf = uitofp i12 %x to half
797  %yf = uitofp i12 %y to half
798  %r = fsub half %xf, %yf
799  ret half %r
800}
801
802define half @test_ui_ui_i12_sub_fail_overflow(i12 noundef %x_in, i12 noundef %y_in) {
803; CHECK-LABEL: @test_ui_ui_i12_sub_fail_overflow(
804; CHECK-NEXT:    [[X:%.*]] = and i12 [[X_IN:%.*]], 1023
805; CHECK-NEXT:    [[Y:%.*]] = and i12 [[Y_IN:%.*]], 2047
806; CHECK-NEXT:    [[TMP1:%.*]] = sub nsw i12 [[X]], [[Y]]
807; CHECK-NEXT:    [[R:%.*]] = sitofp i12 [[TMP1]] to half
808; CHECK-NEXT:    ret half [[R]]
809;
810  %x = and i12 %x_in, 1023
811  %y = and i12 %y_in, 2047
812  %xf = uitofp i12 %x to half
813  %yf = uitofp i12 %y to half
814  %r = fsub half %xf, %yf
815  ret half %r
816}
817
818
819define half @test_si_si_i12_sub(i12 noundef %x_in, i12 noundef %y_in) {
820; CHECK-LABEL: @test_si_si_i12_sub(
821; CHECK-NEXT:    [[X:%.*]] = and i12 [[X_IN:%.*]], 1023
822; CHECK-NEXT:    [[Y:%.*]] = or i12 [[Y_IN:%.*]], -1024
823; CHECK-NEXT:    [[TMP1:%.*]] = sub nsw i12 [[X]], [[Y]]
824; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i12 [[TMP1]] to half
825; CHECK-NEXT:    ret half [[R]]
826;
827  %x = and i12 %x_in, 1023
828  %y = or i12 %y_in, -1024
829  %xf = sitofp i12 %x to half
830  %yf = sitofp i12 %y to half
831  %r = fsub half %xf, %yf
832  ret half %r
833}
834
835define half @test_si_si_i12_sub_fail_overflow(i12 noundef %x, i12 noundef %y) {
836; CHECK-LABEL: @test_si_si_i12_sub_fail_overflow(
837; CHECK-NEXT:    [[XF:%.*]] = sitofp i12 [[X:%.*]] to half
838; CHECK-NEXT:    [[YF:%.*]] = sitofp i12 [[Y:%.*]] to half
839; CHECK-NEXT:    [[R:%.*]] = fsub half [[XF]], [[YF]]
840; CHECK-NEXT:    ret half [[R]]
841;
842  %xf = sitofp i12 %x to half
843  %yf = sitofp i12 %y to half
844  %r = fsub half %xf, %yf
845  ret half %r
846}
847
848define half @test_ui_ui_i12_mul(i12 noundef %x_in, i12 noundef %y_in) {
849; CHECK-LABEL: @test_ui_ui_i12_mul(
850; CHECK-NEXT:    [[X:%.*]] = and i12 [[X_IN:%.*]], 31
851; CHECK-NEXT:    [[Y:%.*]] = and i12 [[Y_IN:%.*]], 63
852; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw nsw i12 [[X]], [[Y]]
853; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i12 [[TMP1]] to half
854; CHECK-NEXT:    ret half [[R]]
855;
856  %x = and i12 %x_in, 31
857  %y = and i12 %y_in, 63
858  %xf = uitofp i12 %x to half
859  %yf = uitofp i12 %y to half
860  %r = fmul half %xf, %yf
861  ret half %r
862}
863
864define half @test_ui_ui_i12_mul_fail_overflow(i12 noundef %x_in, i12 noundef %y_in) {
865; CHECK-LABEL: @test_ui_ui_i12_mul_fail_overflow(
866; CHECK-NEXT:    [[XX:%.*]] = and i12 [[X_IN:%.*]], 31
867; CHECK-NEXT:    [[X:%.*]] = add nuw nsw i12 [[XX]], 1
868; CHECK-NEXT:    [[Y:%.*]] = and i12 [[Y_IN:%.*]], 63
869; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw i12 [[X]], [[Y]]
870; CHECK-NEXT:    [[R:%.*]] = uitofp i12 [[TMP1]] to half
871; CHECK-NEXT:    ret half [[R]]
872;
873  %xx = and i12 %x_in, 31
874  %x = add i12 %xx, 1
875  %y = and i12 %y_in, 63
876  %xf = uitofp i12 %x to half
877  %yf = uitofp i12 %y to half
878  %r = fmul half %xf, %yf
879  ret half %r
880}
881
882define half @test_ui_ui_i12_mul_C(i12 noundef %x_in) {
883; CHECK-LABEL: @test_ui_ui_i12_mul_C(
884; CHECK-NEXT:    [[X:%.*]] = shl i12 [[X_IN:%.*]], 6
885; CHECK-NEXT:    [[TMP1:%.*]] = and i12 [[X]], 1984
886; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i12 [[TMP1]] to half
887; CHECK-NEXT:    ret half [[R]]
888;
889  %x = and i12 %x_in, 31
890  %xf = uitofp i12 %x to half
891  %r = fmul half %xf, 64.0
892  ret half %r
893}
894
895define half @test_si_si_i12_mul(i12 noundef %x_in, i12 noundef %y_in) {
896; CHECK-LABEL: @test_si_si_i12_mul(
897; CHECK-NEXT:    [[XX:%.*]] = and i12 [[X_IN:%.*]], 30
898; CHECK-NEXT:    [[X:%.*]] = or disjoint i12 [[XX]], 1
899; CHECK-NEXT:    [[Y:%.*]] = or i12 [[Y_IN:%.*]], -64
900; CHECK-NEXT:    [[TMP1:%.*]] = mul nsw i12 [[X]], [[Y]]
901; CHECK-NEXT:    [[R:%.*]] = sitofp i12 [[TMP1]] to half
902; CHECK-NEXT:    ret half [[R]]
903;
904  %xx = and i12 %x_in, 30
905  %x = add nsw nuw i12 %xx, 1
906  %y = or i12 %y_in, -64
907  %xf = sitofp i12 %x to half
908  %yf = sitofp i12 %y to half
909  %r = fmul half %xf, %yf
910  ret half %r
911}
912
913define half @test_si_si_i12_mul_fail_overflow(i12 noundef %x_in, i12 noundef %y_in) {
914; CHECK-LABEL: @test_si_si_i12_mul_fail_overflow(
915; CHECK-NEXT:    [[XX:%.*]] = and i12 [[X_IN:%.*]], 30
916; CHECK-NEXT:    [[X:%.*]] = or disjoint i12 [[XX]], 1
917; CHECK-NEXT:    [[Y:%.*]] = or i12 [[Y_IN:%.*]], -128
918; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i12 [[X]] to half
919; CHECK-NEXT:    [[YF:%.*]] = sitofp i12 [[Y]] to half
920; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], [[YF]]
921; CHECK-NEXT:    ret half [[R]]
922;
923  %xx = and i12 %x_in, 30
924  %x = add nsw nuw i12 %xx, 1
925  %y = or i12 %y_in, -128
926  %xf = sitofp i12 %x to half
927  %yf = sitofp i12 %y to half
928  %r = fmul half %xf, %yf
929  ret half %r
930}
931
932define half @test_si_si_i12_mul_fail_maybe_non_zero(i12 noundef %x_in, i12 noundef %y_in) {
933; CHECK-LABEL: @test_si_si_i12_mul_fail_maybe_non_zero(
934; CHECK-NEXT:    [[X:%.*]] = and i12 [[X_IN:%.*]], 30
935; CHECK-NEXT:    [[Y:%.*]] = or i12 [[Y_IN:%.*]], -128
936; CHECK-NEXT:    [[XF:%.*]] = uitofp nneg i12 [[X]] to half
937; CHECK-NEXT:    [[YF:%.*]] = sitofp i12 [[Y]] to half
938; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], [[YF]]
939; CHECK-NEXT:    ret half [[R]]
940;
941  %x = and i12 %x_in, 30
942  %y = or i12 %y_in, -128
943  %xf = sitofp i12 %x to half
944  %yf = sitofp i12 %y to half
945  %r = fmul half %xf, %yf
946  ret half %r
947}
948
949define half @test_si_si_i12_mul_C(i12 noundef %x_in) {
950; CHECK-LABEL: @test_si_si_i12_mul_C(
951; CHECK-NEXT:    [[X:%.*]] = or i12 [[X_IN:%.*]], -64
952; CHECK-NEXT:    [[TMP1:%.*]] = mul nsw i12 [[X]], -16
953; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i12 [[TMP1]] to half
954; CHECK-NEXT:    ret half [[R]]
955;
956  %x = or i12 %x_in, -64
957  %xf = sitofp i12 %x to half
958  %r = fmul half %xf, -16.0
959  ret half %r
960}
961
962define half @test_si_si_i12_mul_C_fail_overflow(i12 noundef %x_in) {
963; CHECK-LABEL: @test_si_si_i12_mul_C_fail_overflow(
964; CHECK-NEXT:    [[X:%.*]] = or i12 [[X_IN:%.*]], -64
965; CHECK-NEXT:    [[XF:%.*]] = sitofp i12 [[X]] to half
966; CHECK-NEXT:    [[R:%.*]] = fmul half [[XF]], 0xHD400
967; CHECK-NEXT:    ret half [[R]]
968;
969  %x = or i12 %x_in, -64
970  %xf = sitofp i12 %x to half
971  %r = fmul half %xf, -64.0
972  ret half %r
973}
974
975define half @test_ui_si_i12_mul_nsw(i12 noundef %x_in, i12 noundef %y_in) {
976; CHECK-LABEL: @test_ui_si_i12_mul_nsw(
977; CHECK-NEXT:    [[XX:%.*]] = and i12 [[X_IN:%.*]], 31
978; CHECK-NEXT:    [[X:%.*]] = add nuw nsw i12 [[XX]], 1
979; CHECK-NEXT:    [[YY:%.*]] = and i12 [[Y_IN:%.*]], 30
980; CHECK-NEXT:    [[Y:%.*]] = or disjoint i12 [[YY]], 1
981; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw nsw i12 [[X]], [[Y]]
982; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i12 [[TMP1]] to half
983; CHECK-NEXT:    ret half [[R]]
984;
985  %xx = and i12 %x_in, 31
986  %x = add i12 %xx, 1
987  %yy = and i12 %y_in, 30
988  %y = add i12 %yy, 1
989  %xf = uitofp i12 %x to half
990  %yf = sitofp i12 %y to half
991  %r = fmul half %xf, %yf
992  ret half %r
993}
994
995define float @test_ui_add_with_signed_constant(i32 %shr.i) {
996; CHECK-LABEL: @test_ui_add_with_signed_constant(
997; CHECK-NEXT:    [[AND_I:%.*]] = and i32 [[SHR_I:%.*]], 32767
998; CHECK-NEXT:    [[TMP1:%.*]] = add nsw i32 [[AND_I]], -16383
999; CHECK-NEXT:    [[ADD:%.*]] = sitofp i32 [[TMP1]] to float
1000; CHECK-NEXT:    ret float [[ADD]]
1001;
1002  %and.i = and i32 %shr.i, 32767
1003  %sub = uitofp i32 %and.i to float
1004  %add = fadd float %sub, -16383.0
1005  ret float %add
1006}
1007
1008
1009;; Reduced form of bug noticed due to #82555
1010define float @missed_nonzero_check_on_constant_for_si_fmul(i1 %c, i1 %.b, ptr %g_2345) {
1011; CHECK-LABEL: @missed_nonzero_check_on_constant_for_si_fmul(
1012; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1013; CHECK-NEXT:    [[CONV_I:%.*]] = trunc nuw i32 [[SEL]] to i16
1014; CHECK-NEXT:    [[CONV1_I:%.*]] = sitofp i16 [[CONV_I]] to float
1015; CHECK-NEXT:    [[MUL3_I_I:%.*]] = call float @llvm.copysign.f32(float 0.000000e+00, float [[CONV1_I]])
1016; CHECK-NEXT:    store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
1017; CHECK-NEXT:    ret float [[MUL3_I_I]]
1018;
1019  %sel = select i1 %c, i32 65529, i32 53264
1020  %conv.i = trunc i32 %sel to i16
1021  %conv1.i = sitofp i16 %conv.i to float
1022  %mul3.i.i = fmul float %conv1.i, 0.000000e+00
1023  store i32 %sel, ptr %g_2345, align 4
1024  ret float %mul3.i.i
1025}
1026
1027define <2 x float> @missed_nonzero_check_on_constant_for_si_fmul_vec(i1 %c, i1 %.b, ptr %g_2345) {
1028; CHECK-LABEL: @missed_nonzero_check_on_constant_for_si_fmul_vec(
1029; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1030; CHECK-NEXT:    [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16
1031; CHECK-NEXT:    [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
1032; CHECK-NEXT:    [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
1033; CHECK-NEXT:    [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>
1034; CHECK-NEXT:    [[MUL3_I_I:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> zeroinitializer, <2 x float> [[CONV1_I]])
1035; CHECK-NEXT:    store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
1036; CHECK-NEXT:    ret <2 x float> [[MUL3_I_I]]
1037;
1038  %sel = select i1 %c, i32 65529, i32 53264
1039  %conv.i.s = trunc i32 %sel to i16
1040  %conv.i.v = insertelement <2 x i16> poison, i16 %conv.i.s, i64 0
1041  %conv.i = insertelement <2 x i16> %conv.i.v, i16 %conv.i.s, i64 1
1042  %conv1.i = sitofp <2 x i16> %conv.i to <2 x float>
1043  %mul3.i.i = fmul <2 x float> %conv1.i, zeroinitializer
1044  store i32 %sel, ptr %g_2345, align 4
1045  ret <2 x float> %mul3.i.i
1046}
1047
1048define float @negzero_check_on_constant_for_si_fmul(i1 %c, i1 %.b, ptr %g_2345) {
1049; CHECK-LABEL: @negzero_check_on_constant_for_si_fmul(
1050; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1051; CHECK-NEXT:    [[CONV_I:%.*]] = trunc nuw i32 [[SEL]] to i16
1052; CHECK-NEXT:    [[CONV1_I:%.*]] = sitofp i16 [[CONV_I]] to float
1053; CHECK-NEXT:    [[TMP1:%.*]] = fneg float [[CONV1_I]]
1054; CHECK-NEXT:    [[MUL3_I_I:%.*]] = call float @llvm.copysign.f32(float 0.000000e+00, float [[TMP1]])
1055; CHECK-NEXT:    store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
1056; CHECK-NEXT:    ret float [[MUL3_I_I]]
1057;
1058  %sel = select i1 %c, i32 65529, i32 53264
1059  %conv.i = trunc i32 %sel to i16
1060  %conv1.i = sitofp i16 %conv.i to float
1061  %mul3.i.i = fmul float %conv1.i, -0.000000e+00
1062  store i32 %sel, ptr %g_2345, align 4
1063  ret float %mul3.i.i
1064}
1065
1066define <2 x float> @nonzero_check_on_constant_for_si_fmul_vec_w_poison(i1 %c, i1 %.b, ptr %g_2345) {
1067; CHECK-LABEL: @nonzero_check_on_constant_for_si_fmul_vec_w_poison(
1068; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1069; CHECK-NEXT:    [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16
1070; CHECK-NEXT:    [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
1071; CHECK-NEXT:    [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
1072; CHECK-NEXT:    [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>
1073; CHECK-NEXT:    [[MUL3_I_I:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> <float poison, float 0.000000e+00>, <2 x float> [[CONV1_I]])
1074; CHECK-NEXT:    store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
1075; CHECK-NEXT:    ret <2 x float> [[MUL3_I_I]]
1076;
1077  %sel = select i1 %c, i32 65529, i32 53264
1078  %conv.i.s = trunc i32 %sel to i16
1079  %conv.i.v = insertelement <2 x i16> poison, i16 %conv.i.s, i64 0
1080  %conv.i = insertelement <2 x i16> %conv.i.v, i16 %conv.i.s, i64 1
1081  %conv1.i = sitofp <2 x i16> %conv.i to <2 x float>
1082  %mul3.i.i = fmul <2 x float> %conv1.i, <float poison, float 0.000000e+00>
1083  store i32 %sel, ptr %g_2345, align 4
1084  ret <2 x float> %mul3.i.i
1085}
1086
1087define <2 x float> @nonzero_check_on_constant_for_si_fmul_nz_vec_w_poison(i1 %c, i1 %.b, ptr %g_2345) {
1088; CHECK-LABEL: @nonzero_check_on_constant_for_si_fmul_nz_vec_w_poison(
1089; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1090; CHECK-NEXT:    [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16
1091; CHECK-NEXT:    [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
1092; CHECK-NEXT:    [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
1093; CHECK-NEXT:    [[MUL3_I_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>
1094; CHECK-NEXT:    store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
1095; CHECK-NEXT:    ret <2 x float> [[MUL3_I_I]]
1096;
1097  %sel = select i1 %c, i32 65529, i32 53264
1098  %conv.i.s = trunc i32 %sel to i16
1099  %conv.i.v = insertelement <2 x i16> poison, i16 %conv.i.s, i64 0
1100  %conv.i = insertelement <2 x i16> %conv.i.v, i16 %conv.i.s, i64 1
1101  %conv1.i = sitofp <2 x i16> %conv.i to <2 x float>
1102  %mul3.i.i = fmul <2 x float> %conv1.i, <float poison, float 1.000000e+00>
1103  store i32 %sel, ptr %g_2345, align 4
1104  ret <2 x float> %mul3.i.i
1105}
1106
1107define <2 x float> @nonzero_check_on_constant_for_si_fmul_negz_vec_w_poison(i1 %c, i1 %.b, ptr %g_2345) {
1108; CHECK-LABEL: @nonzero_check_on_constant_for_si_fmul_negz_vec_w_poison(
1109; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1110; CHECK-NEXT:    [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16
1111; CHECK-NEXT:    [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
1112; CHECK-NEXT:    [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
1113; CHECK-NEXT:    [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>
1114; CHECK-NEXT:    [[TMP1:%.*]] = fneg <2 x float> [[CONV1_I]]
1115; CHECK-NEXT:    [[MUL3_I_I:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> <float poison, float -0.000000e+00>, <2 x float> [[TMP1]])
1116; CHECK-NEXT:    store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
1117; CHECK-NEXT:    ret <2 x float> [[MUL3_I_I]]
1118;
1119  %sel = select i1 %c, i32 65529, i32 53264
1120  %conv.i.s = trunc i32 %sel to i16
1121  %conv.i.v = insertelement <2 x i16> poison, i16 %conv.i.s, i64 0
1122  %conv.i = insertelement <2 x i16> %conv.i.v, i16 %conv.i.s, i64 1
1123  %conv1.i = sitofp <2 x i16> %conv.i to <2 x float>
1124  %mul3.i.i = fmul <2 x float> %conv1.i, <float poison, float -0.000000e+00>
1125  store i32 %sel, ptr %g_2345, align 4
1126  ret <2 x float> %mul3.i.i
1127}
1128