1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4declare float @llvm.minnum.f32(float, float)
5declare float @llvm.maxnum.f32(float, float)
6declare float @llvm.minimum.f32(float, float)
7declare float @llvm.maximum.f32(float, float)
8declare <2 x float> @llvm.minnum.v2f32(<2 x float>, <2 x float>)
9declare <2 x float> @llvm.maxnum.v2f32(<2 x float>, <2 x float>)
10declare <2 x float> @llvm.minimum.v2f32(<2 x float>, <2 x float>)
11declare <2 x float> @llvm.maximum.v2f32(<2 x float>, <2 x float>)
12
13declare double @llvm.minnum.f64(double, double)
14declare double @llvm.maxnum.f64(double, double)
15declare <2 x double> @llvm.minnum.v2f64(<2 x double>, <2 x double>)
16declare <2 x double> @llvm.maxnum.v2f64(<2 x double>, <2 x double>)
17declare double @llvm.minimum.f64(double, double)
18declare double @llvm.maximum.f64(double, double)
19declare <2 x double> @llvm.minimum.v2f64(<2 x double>, <2 x double>)
20declare <2 x double> @llvm.maximum.v2f64(<2 x double>, <2 x double>)
21
22define float @test_minnum_const_nan(float %x) {
23; CHECK-LABEL: @test_minnum_const_nan(
24; CHECK-NEXT:    ret float [[X:%.*]]
25;
26  %r = call float @llvm.minnum.f32(float %x, float 0x7fff000000000000)
27  ret float %r
28}
29
30define float @test_maxnum_const_nan(float %x) {
31; CHECK-LABEL: @test_maxnum_const_nan(
32; CHECK-NEXT:    ret float [[X:%.*]]
33;
34  %r = call float @llvm.maxnum.f32(float %x, float 0x7fff000000000000)
35  ret float %r
36}
37
38define float @test_maximum_const_nan(float %x) {
39; CHECK-LABEL: @test_maximum_const_nan(
40; CHECK-NEXT:    ret float 0x7FFF000000000000
41;
42  %r = call float @llvm.maximum.f32(float %x, float 0x7fff000000000000)
43  ret float %r
44}
45
46define float @test_minimum_const_nan(float %x) {
47; CHECK-LABEL: @test_minimum_const_nan(
48; CHECK-NEXT:    ret float 0x7FFF000000000000
49;
50  %r = call float @llvm.minimum.f32(float %x, float 0x7fff000000000000)
51  ret float %r
52}
53
54define float @test_minnum_const_inf(float %x) {
55; CHECK-LABEL: @test_minnum_const_inf(
56; CHECK-NEXT:    [[R:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float 0x7FF0000000000000)
57; CHECK-NEXT:    ret float [[R]]
58;
59  %r = call float @llvm.minnum.f32(float %x, float 0x7ff0000000000000)
60  ret float %r
61}
62
63define float @test_maxnum_const_inf(float %x) {
64; CHECK-LABEL: @test_maxnum_const_inf(
65; CHECK-NEXT:    ret float 0x7FF0000000000000
66;
67  %r = call float @llvm.maxnum.f32(float %x, float 0x7ff0000000000000)
68  ret float %r
69}
70
71define float @test_maximum_const_inf(float %x) {
72; CHECK-LABEL: @test_maximum_const_inf(
73; CHECK-NEXT:    [[R:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float 0x7FF0000000000000)
74; CHECK-NEXT:    ret float [[R]]
75;
76  %r = call float @llvm.maximum.f32(float %x, float 0x7ff0000000000000)
77  ret float %r
78}
79
80define float @test_minimum_const_inf(float %x) {
81; CHECK-LABEL: @test_minimum_const_inf(
82; CHECK-NEXT:    ret float [[X:%.*]]
83;
84  %r = call float @llvm.minimum.f32(float %x, float 0x7ff0000000000000)
85  ret float %r
86}
87
88define float @test_minnum_const_neg_inf(float %x) {
89; CHECK-LABEL: @test_minnum_const_neg_inf(
90; CHECK-NEXT:    ret float 0xFFF0000000000000
91;
92  %r = call float @llvm.minnum.f32(float %x, float 0xfff0000000000000)
93  ret float %r
94}
95
96define float @test_maxnum_const_neg_inf(float %x) {
97; CHECK-LABEL: @test_maxnum_const_neg_inf(
98; CHECK-NEXT:    [[R:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 0xFFF0000000000000)
99; CHECK-NEXT:    ret float [[R]]
100;
101  %r = call float @llvm.maxnum.f32(float %x, float 0xfff0000000000000)
102  ret float %r
103}
104
105define float @test_maximum_const_neg_inf(float %x) {
106; CHECK-LABEL: @test_maximum_const_neg_inf(
107; CHECK-NEXT:    ret float [[X:%.*]]
108;
109  %r = call float @llvm.maximum.f32(float %x, float 0xfff0000000000000)
110  ret float %r
111}
112
113define float @test_minimum_const_neg_inf(float %x) {
114; CHECK-LABEL: @test_minimum_const_neg_inf(
115; CHECK-NEXT:    [[R:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float 0xFFF0000000000000)
116; CHECK-NEXT:    ret float [[R]]
117;
118  %r = call float @llvm.minimum.f32(float %x, float 0xfff0000000000000)
119  ret float %r
120}
121
122define float @test_minnum_const_inf_nnan(float %x) {
123; CHECK-LABEL: @test_minnum_const_inf_nnan(
124; CHECK-NEXT:    ret float [[X:%.*]]
125;
126  %r = call nnan float @llvm.minnum.f32(float %x, float 0x7ff0000000000000)
127  ret float %r
128}
129
130define float @test_maxnum_const_inf_nnan(float %x) {
131; CHECK-LABEL: @test_maxnum_const_inf_nnan(
132; CHECK-NEXT:    ret float 0x7FF0000000000000
133;
134  %r = call nnan float @llvm.maxnum.f32(float %x, float 0x7ff0000000000000)
135  ret float %r
136}
137
138define float @test_maximum_const_inf_nnan(float %x) {
139; CHECK-LABEL: @test_maximum_const_inf_nnan(
140; CHECK-NEXT:    ret float 0x7FF0000000000000
141;
142  %r = call nnan float @llvm.maximum.f32(float %x, float 0x7ff0000000000000)
143  ret float %r
144}
145
146define float @test_minimum_const_inf_nnan(float %x) {
147; CHECK-LABEL: @test_minimum_const_inf_nnan(
148; CHECK-NEXT:    ret float [[X:%.*]]
149;
150  %r = call nnan float @llvm.minimum.f32(float %x, float 0x7ff0000000000000)
151  ret float %r
152}
153
154define float @test_minnum_const_inf_nnan_comm(float %x) {
155; CHECK-LABEL: @test_minnum_const_inf_nnan_comm(
156; CHECK-NEXT:    ret float [[X:%.*]]
157;
158  %r = call nnan float @llvm.minnum.f32(float 0x7ff0000000000000, float %x)
159  ret float %r
160}
161
162define float @test_maxnum_const_inf_nnan_comm(float %x) {
163; CHECK-LABEL: @test_maxnum_const_inf_nnan_comm(
164; CHECK-NEXT:    ret float 0x7FF0000000000000
165;
166  %r = call nnan float @llvm.maxnum.f32(float 0x7ff0000000000000, float %x)
167  ret float %r
168}
169
170define float @test_maximum_const_inf_nnan_comm(float %x) {
171; CHECK-LABEL: @test_maximum_const_inf_nnan_comm(
172; CHECK-NEXT:    ret float 0x7FF0000000000000
173;
174  %r = call nnan float @llvm.maximum.f32(float 0x7ff0000000000000, float %x)
175  ret float %r
176}
177
178define float @test_minimum_const_inf_nnan_comm(float %x) {
179; CHECK-LABEL: @test_minimum_const_inf_nnan_comm(
180; CHECK-NEXT:    ret float [[X:%.*]]
181;
182  %r = call nnan float @llvm.minimum.f32(float 0x7ff0000000000000, float %x)
183  ret float %r
184}
185
186define <2 x float> @test_minnum_const_inf_nnan_comm_vec(<2 x float> %x) {
187; CHECK-LABEL: @test_minnum_const_inf_nnan_comm_vec(
188; CHECK-NEXT:    ret <2 x float> [[X:%.*]]
189;
190  %r = call nnan <2 x float> @llvm.minnum.v2f32(<2 x float> <float 0x7ff0000000000000, float 0x7ff0000000000000>, <2 x float> %x)
191  ret <2 x float> %r
192}
193
194define <2 x float> @test_maxnum_const_inf_nnan_comm_vec(<2 x float> %x) {
195; CHECK-LABEL: @test_maxnum_const_inf_nnan_comm_vec(
196; CHECK-NEXT:    ret <2 x float> <float 0x7FF0000000000000, float 0x7FF0000000000000>
197;
198  %r = call nnan <2 x float> @llvm.maxnum.v2f32(<2 x float> <float 0x7ff0000000000000, float 0x7ff0000000000000>, <2 x float> %x)
199  ret <2 x float> %r
200}
201
202define <2 x float> @test_maximum_const_inf_nnan_comm_vec(<2 x float> %x) {
203; CHECK-LABEL: @test_maximum_const_inf_nnan_comm_vec(
204; CHECK-NEXT:    ret <2 x float> <float 0x7FF0000000000000, float 0x7FF0000000000000>
205;
206  %r = call nnan <2 x float> @llvm.maximum.v2f32(<2 x float> <float 0x7ff0000000000000, float 0x7ff0000000000000>, <2 x float> %x)
207  ret <2 x float> %r
208}
209
210define <2 x float> @test_minimum_const_inf_nnan_comm_vec(<2 x float> %x) {
211; CHECK-LABEL: @test_minimum_const_inf_nnan_comm_vec(
212; CHECK-NEXT:    ret <2 x float> [[X:%.*]]
213;
214  %r = call nnan <2 x float> @llvm.minimum.v2f32(<2 x float> <float 0x7ff0000000000000, float 0x7ff0000000000000>, <2 x float> %x)
215  ret <2 x float> %r
216}
217
218define float @test_minnum_const_neg_inf_nnan(float %x) {
219; CHECK-LABEL: @test_minnum_const_neg_inf_nnan(
220; CHECK-NEXT:    ret float 0xFFF0000000000000
221;
222  %r = call nnan float @llvm.minnum.f32(float %x, float 0xfff0000000000000)
223  ret float %r
224}
225
226define float @test_maxnum_const_neg_inf_nnan(float %x) {
227; CHECK-LABEL: @test_maxnum_const_neg_inf_nnan(
228; CHECK-NEXT:    ret float [[X:%.*]]
229;
230  %r = call nnan float @llvm.maxnum.f32(float %x, float 0xfff0000000000000)
231  ret float %r
232}
233
234define float @test_maximum_const_neg_inf_nnan(float %x) {
235; CHECK-LABEL: @test_maximum_const_neg_inf_nnan(
236; CHECK-NEXT:    ret float [[X:%.*]]
237;
238  %r = call nnan float @llvm.maximum.f32(float %x, float 0xfff0000000000000)
239  ret float %r
240}
241
242define float @test_minimum_const_neg_inf_nnan(float %x) {
243; CHECK-LABEL: @test_minimum_const_neg_inf_nnan(
244; CHECK-NEXT:    ret float 0xFFF0000000000000
245;
246  %r = call nnan float @llvm.minimum.f32(float %x, float 0xfff0000000000000)
247  ret float %r
248}
249
250define float @test_minnum_const_max(float %x) {
251; CHECK-LABEL: @test_minnum_const_max(
252; CHECK-NEXT:    [[R:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float 0x47EFFFFFE0000000)
253; CHECK-NEXT:    ret float [[R]]
254;
255  %r = call float @llvm.minnum.f32(float %x, float 0x47efffffe0000000)
256  ret float %r
257}
258
259define float @test_maxnum_const_max(float %x) {
260; CHECK-LABEL: @test_maxnum_const_max(
261; CHECK-NEXT:    [[R:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 0x47EFFFFFE0000000)
262; CHECK-NEXT:    ret float [[R]]
263;
264  %r = call float @llvm.maxnum.f32(float %x, float 0x47efffffe0000000)
265  ret float %r
266}
267
268define float @test_maximum_const_max(float %x) {
269; CHECK-LABEL: @test_maximum_const_max(
270; CHECK-NEXT:    [[R:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float 0x47EFFFFFE0000000)
271; CHECK-NEXT:    ret float [[R]]
272;
273  %r = call float @llvm.maximum.f32(float %x, float 0x47efffffe0000000)
274  ret float %r
275}
276
277define float @test_minimum_const_max(float %x) {
278; CHECK-LABEL: @test_minimum_const_max(
279; CHECK-NEXT:    [[R:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float 0x47EFFFFFE0000000)
280; CHECK-NEXT:    ret float [[R]]
281;
282  %r = call float @llvm.minimum.f32(float %x, float 0x47efffffe0000000)
283  ret float %r
284}
285
286define float @test_minnum_const_neg_max(float %x) {
287; CHECK-LABEL: @test_minnum_const_neg_max(
288; CHECK-NEXT:    [[R:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float 0xC7EFFFFFE0000000)
289; CHECK-NEXT:    ret float [[R]]
290;
291  %r = call float @llvm.minnum.f32(float %x, float 0xc7efffffe0000000)
292  ret float %r
293}
294
295define float @test_maxnum_const_neg_max(float %x) {
296; CHECK-LABEL: @test_maxnum_const_neg_max(
297; CHECK-NEXT:    [[R:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 0xC7EFFFFFE0000000)
298; CHECK-NEXT:    ret float [[R]]
299;
300  %r = call float @llvm.maxnum.f32(float %x, float 0xc7efffffe0000000)
301  ret float %r
302}
303
304define float @test_maximum_const_neg_max(float %x) {
305; CHECK-LABEL: @test_maximum_const_neg_max(
306; CHECK-NEXT:    [[R:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float 0xC7EFFFFFE0000000)
307; CHECK-NEXT:    ret float [[R]]
308;
309  %r = call float @llvm.maximum.f32(float %x, float 0xc7efffffe0000000)
310  ret float %r
311}
312
313define float @test_minimum_const_neg_max(float %x) {
314; CHECK-LABEL: @test_minimum_const_neg_max(
315; CHECK-NEXT:    [[R:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float 0xC7EFFFFFE0000000)
316; CHECK-NEXT:    ret float [[R]]
317;
318  %r = call float @llvm.minimum.f32(float %x, float 0xc7efffffe0000000)
319  ret float %r
320}
321
322define float @test_minnum_const_max_ninf(float %x) {
323; CHECK-LABEL: @test_minnum_const_max_ninf(
324; CHECK-NEXT:    [[R:%.*]] = call ninf float @llvm.minnum.f32(float [[X:%.*]], float 0x47EFFFFFE0000000)
325; CHECK-NEXT:    ret float [[R]]
326;
327  %r = call ninf float @llvm.minnum.f32(float %x, float 0x47efffffe0000000)
328  ret float %r
329}
330
331define float @test_maxnum_const_max_ninf(float %x) {
332; CHECK-LABEL: @test_maxnum_const_max_ninf(
333; CHECK-NEXT:    ret float 0x47EFFFFFE0000000
334;
335  %r = call ninf float @llvm.maxnum.f32(float %x, float 0x47efffffe0000000)
336  ret float %r
337}
338
339define float @test_maximum_const_max_ninf(float %x) {
340; CHECK-LABEL: @test_maximum_const_max_ninf(
341; CHECK-NEXT:    [[R:%.*]] = call ninf float @llvm.maximum.f32(float [[X:%.*]], float 0x47EFFFFFE0000000)
342; CHECK-NEXT:    ret float [[R]]
343;
344  %r = call ninf float @llvm.maximum.f32(float %x, float 0x47efffffe0000000)
345  ret float %r
346}
347
348define float @test_minimum_const_max_ninf(float %x) {
349; CHECK-LABEL: @test_minimum_const_max_ninf(
350; CHECK-NEXT:    ret float [[X:%.*]]
351;
352  %r = call ninf float @llvm.minimum.f32(float %x, float 0x47efffffe0000000)
353  ret float %r
354}
355
356define float @test_minnum_const_neg_max_ninf(float %x) {
357; CHECK-LABEL: @test_minnum_const_neg_max_ninf(
358; CHECK-NEXT:    ret float 0xC7EFFFFFE0000000
359;
360  %r = call ninf float @llvm.minnum.f32(float %x, float 0xc7efffffe0000000)
361  ret float %r
362}
363
364define float @test_maxnum_const_neg_max_ninf(float %x) {
365; CHECK-LABEL: @test_maxnum_const_neg_max_ninf(
366; CHECK-NEXT:    [[R:%.*]] = call ninf float @llvm.maxnum.f32(float [[X:%.*]], float 0xC7EFFFFFE0000000)
367; CHECK-NEXT:    ret float [[R]]
368;
369  %r = call ninf float @llvm.maxnum.f32(float %x, float 0xc7efffffe0000000)
370  ret float %r
371}
372
373define float @test_maximum_const_neg_max_ninf(float %x) {
374; CHECK-LABEL: @test_maximum_const_neg_max_ninf(
375; CHECK-NEXT:    ret float [[X:%.*]]
376;
377  %r = call ninf float @llvm.maximum.f32(float %x, float 0xc7efffffe0000000)
378  ret float %r
379}
380
381define float @test_minimum_const_neg_max_ninf(float %x) {
382; CHECK-LABEL: @test_minimum_const_neg_max_ninf(
383; CHECK-NEXT:    [[R:%.*]] = call ninf float @llvm.minimum.f32(float [[X:%.*]], float 0xC7EFFFFFE0000000)
384; CHECK-NEXT:    ret float [[R]]
385;
386  %r = call ninf float @llvm.minimum.f32(float %x, float 0xc7efffffe0000000)
387  ret float %r
388}
389
390define float @test_minnum_const_max_nnan_ninf(float %x) {
391; CHECK-LABEL: @test_minnum_const_max_nnan_ninf(
392; CHECK-NEXT:    ret float [[X:%.*]]
393;
394  %r = call nnan ninf float @llvm.minnum.f32(float %x, float 0x47efffffe0000000)
395  ret float %r
396}
397
398define float @test_maxnum_const_max_nnan_ninf(float %x) {
399; CHECK-LABEL: @test_maxnum_const_max_nnan_ninf(
400; CHECK-NEXT:    ret float 0x47EFFFFFE0000000
401;
402  %r = call nnan ninf float @llvm.maxnum.f32(float %x, float 0x47efffffe0000000)
403  ret float %r
404}
405
406define float @test_maximum_const_max_nnan_ninf(float %x) {
407; CHECK-LABEL: @test_maximum_const_max_nnan_ninf(
408; CHECK-NEXT:    ret float 0x47EFFFFFE0000000
409;
410  %r = call nnan ninf float @llvm.maximum.f32(float %x, float 0x47efffffe0000000)
411  ret float %r
412}
413
414define float @test_minimum_const_max_nnan_ninf(float %x) {
415; CHECK-LABEL: @test_minimum_const_max_nnan_ninf(
416; CHECK-NEXT:    ret float [[X:%.*]]
417;
418  %r = call nnan ninf float @llvm.minimum.f32(float %x, float 0x47efffffe0000000)
419  ret float %r
420}
421
422define float @test_minnum_const_neg_max_nnan_ninf(float %x) {
423; CHECK-LABEL: @test_minnum_const_neg_max_nnan_ninf(
424; CHECK-NEXT:    ret float 0xC7EFFFFFE0000000
425;
426  %r = call nnan ninf float @llvm.minnum.f32(float %x, float 0xc7efffffe0000000)
427  ret float %r
428}
429
430define float @test_maxnum_const_neg_max_nnan_ninf(float %x) {
431; CHECK-LABEL: @test_maxnum_const_neg_max_nnan_ninf(
432; CHECK-NEXT:    ret float [[X:%.*]]
433;
434  %r = call nnan ninf float @llvm.maxnum.f32(float %x, float 0xc7efffffe0000000)
435  ret float %r
436}
437
438define float @test_maximum_const_neg_max_nnan_ninf(float %x) {
439; CHECK-LABEL: @test_maximum_const_neg_max_nnan_ninf(
440; CHECK-NEXT:    ret float [[X:%.*]]
441;
442  %r = call nnan ninf float @llvm.maximum.f32(float %x, float 0xc7efffffe0000000)
443  ret float %r
444}
445
446define float @test_minimum_const_neg_max_nnan_ninf(float %x) {
447; CHECK-LABEL: @test_minimum_const_neg_max_nnan_ninf(
448; CHECK-NEXT:    ret float 0xC7EFFFFFE0000000
449;
450  %r = call nnan ninf float @llvm.minimum.f32(float %x, float 0xc7efffffe0000000)
451  ret float %r
452}
453
454; From the LangRef for minnum/maxnum:
455; "If either operand is a NaN, returns the other non-NaN operand."
456
457define double @maxnum_nan_op0(double %x) {
458; CHECK-LABEL: @maxnum_nan_op0(
459; CHECK-NEXT:    ret double [[X:%.*]]
460;
461  %r = call double @llvm.maxnum.f64(double 0x7ff8000000000000, double %x)
462  ret double %r
463}
464
465define double @maxnum_nan_op1(double %x) {
466; CHECK-LABEL: @maxnum_nan_op1(
467; CHECK-NEXT:    ret double [[X:%.*]]
468;
469  %r = call double @llvm.maxnum.f64(double %x, double 0x7ff800000000dead)
470  ret double %r
471}
472
473define double @minnum_nan_op0(double %x) {
474; CHECK-LABEL: @minnum_nan_op0(
475; CHECK-NEXT:    ret double [[X:%.*]]
476;
477  %r = call double @llvm.minnum.f64(double 0x7ff8000dead00000, double %x)
478  ret double %r
479}
480
481define double @minnum_nan_op1(double %x) {
482; CHECK-LABEL: @minnum_nan_op1(
483; CHECK-NEXT:    ret double [[X:%.*]]
484;
485  %r = call double @llvm.minnum.f64(double %x, double 0x7ff800dead00dead)
486  ret double %r
487}
488
489define <2 x double> @maxnum_nan_op0_vec(<2 x double> %x) {
490; CHECK-LABEL: @maxnum_nan_op0_vec(
491; CHECK-NEXT:    ret <2 x double> [[X:%.*]]
492;
493  %r = call <2 x double> @llvm.maxnum.v2f64(<2 x double> <double 0x7ff8000000000000, double undef>, <2 x double> %x)
494  ret <2 x double> %r
495}
496
497define <2 x double> @maxnum_nan_op1_vec(<2 x double> %x) {
498; CHECK-LABEL: @maxnum_nan_op1_vec(
499; CHECK-NEXT:    ret <2 x double> [[X:%.*]]
500;
501  %r = call <2 x double> @llvm.maxnum.v2f64(<2 x double> %x, <2 x double> <double 0x7ff800000000dead, double 0x7ff8ffffffffffff>)
502  ret <2 x double> %r
503}
504
505define <2 x double> @minnum_nan_op0_vec(<2 x double> %x) {
506; CHECK-LABEL: @minnum_nan_op0_vec(
507; CHECK-NEXT:    ret <2 x double> [[X:%.*]]
508;
509  %r = call <2 x double> @llvm.minnum.v2f64(<2 x double> <double undef, double 0x7ff8000dead00000>, <2 x double> %x)
510  ret <2 x double> %r
511}
512
513define <2 x double> @minnum_nan_op1_vec(<2 x double> %x) {
514; CHECK-LABEL: @minnum_nan_op1_vec(
515; CHECK-NEXT:    ret <2 x double> [[X:%.*]]
516;
517  %r = call <2 x double> @llvm.minnum.v2f64(<2 x double> %x, <2 x double> <double 0x7ff800dead00dead, double 0x7ff800dead00dead>)
518  ret <2 x double> %r
519}
520
521define float @maxnum_undef_op1(float %x) {
522; CHECK-LABEL: @maxnum_undef_op1(
523; CHECK-NEXT:    ret float [[X:%.*]]
524;
525  %val = call float @llvm.maxnum.f32(float %x, float undef)
526  ret float %val
527}
528
529define float @maxnum_poison_op1(float %x) {
530; CHECK-LABEL: @maxnum_poison_op1(
531; CHECK-NEXT:    ret float [[X:%.*]]
532;
533  %val = call float @llvm.maxnum.f32(float %x, float poison)
534  ret float %val
535}
536
537define float @maxnum_undef_op0(float %x) {
538; CHECK-LABEL: @maxnum_undef_op0(
539; CHECK-NEXT:    ret float [[X:%.*]]
540;
541  %val = call float @llvm.maxnum.f32(float undef, float %x)
542  ret float %val
543}
544
545define float @maxnum_poison_op0(float %x) {
546; CHECK-LABEL: @maxnum_poison_op0(
547; CHECK-NEXT:    ret float [[X:%.*]]
548;
549  %val = call float @llvm.maxnum.f32(float poison, float %x)
550  ret float %val
551}
552
553define float @minnum_undef_op1(float %x) {
554; CHECK-LABEL: @minnum_undef_op1(
555; CHECK-NEXT:    ret float [[X:%.*]]
556;
557  %val = call float @llvm.minnum.f32(float %x, float undef)
558  ret float %val
559}
560
561define float @minnum_poison_op1(float %x) {
562; CHECK-LABEL: @minnum_poison_op1(
563; CHECK-NEXT:    ret float [[X:%.*]]
564;
565  %val = call float @llvm.minnum.f32(float %x, float poison)
566  ret float %val
567}
568
569define float @minnum_undef_op0(float %x) {
570; CHECK-LABEL: @minnum_undef_op0(
571; CHECK-NEXT:    ret float [[X:%.*]]
572;
573  %val = call float @llvm.minnum.f32(float undef, float %x)
574  ret float %val
575}
576
577define float @minnum_poison_op0(float %x) {
578; CHECK-LABEL: @minnum_poison_op0(
579; CHECK-NEXT:    ret float [[X:%.*]]
580;
581  %val = call float @llvm.minnum.f32(float poison, float %x)
582  ret float %val
583}
584
585define float @minnum_undef_undef(float %x) {
586; CHECK-LABEL: @minnum_undef_undef(
587; CHECK-NEXT:    ret float undef
588;
589  %val = call float @llvm.minnum.f32(float undef, float undef)
590  ret float %val
591}
592
593define float @minnum_poison_undef(float %x) {
594; CHECK-LABEL: @minnum_poison_undef(
595; CHECK-NEXT:    ret float undef
596;
597  %val = call float @llvm.minnum.f32(float poison, float undef)
598  ret float %val
599}
600
601define float @minnum_undef_poison(float %x) {
602; CHECK-LABEL: @minnum_undef_poison(
603; CHECK-NEXT:    ret float poison
604;
605  %val = call float @llvm.minnum.f32(float undef, float poison)
606  ret float %val
607}
608
609define float @maxnum_undef_undef(float %x) {
610; CHECK-LABEL: @maxnum_undef_undef(
611; CHECK-NEXT:    ret float undef
612;
613  %val = call float @llvm.maxnum.f32(float undef, float undef)
614  ret float %val
615}
616
617define float @maxnum_poison_undef(float %x) {
618; CHECK-LABEL: @maxnum_poison_undef(
619; CHECK-NEXT:    ret float undef
620;
621  %val = call float @llvm.maxnum.f32(float poison, float undef)
622  ret float %val
623}
624
625define float @maxnum_undef_poison(float %x) {
626; CHECK-LABEL: @maxnum_undef_poison(
627; CHECK-NEXT:    ret float poison
628;
629  %val = call float @llvm.maxnum.f32(float undef, float poison)
630  ret float %val
631}
632
633define float @minnum_same_args(float %x) {
634; CHECK-LABEL: @minnum_same_args(
635; CHECK-NEXT:    ret float [[X:%.*]]
636;
637  %y = call float @llvm.minnum.f32(float %x, float %x)
638  ret float %y
639}
640
641define float @maxnum_same_args(float %x) {
642; CHECK-LABEL: @maxnum_same_args(
643; CHECK-NEXT:    ret float [[X:%.*]]
644;
645  %y = call float @llvm.maxnum.f32(float %x, float %x)
646  ret float %y
647}
648
649define float @minnum_x_minnum_x_y(float %x, float %y) {
650; CHECK-LABEL: @minnum_x_minnum_x_y(
651; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])
652; CHECK-NEXT:    ret float [[A]]
653;
654  %a = call float @llvm.minnum.f32(float %x, float %y)
655  %b = call float @llvm.minnum.f32(float %x, float %a)
656  ret float %b
657}
658
659define float @minnum_y_minnum_x_y(float %x, float %y) {
660; CHECK-LABEL: @minnum_y_minnum_x_y(
661; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])
662; CHECK-NEXT:    ret float [[A]]
663;
664  %a = call float @llvm.minnum.f32(float %x, float %y)
665  %b = call float @llvm.minnum.f32(float %y, float %a)
666  ret float %b
667}
668
669define float @minnum_x_y_minnum_x(float %x, float %y) {
670; CHECK-LABEL: @minnum_x_y_minnum_x(
671; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])
672; CHECK-NEXT:    ret float [[A]]
673;
674  %a = call float @llvm.minnum.f32(float %x, float %y)
675  %b = call float @llvm.minnum.f32(float %a, float %x)
676  ret float %b
677}
678
679define float @minnum_x_y_minnum_y(float %x, float %y) {
680; CHECK-LABEL: @minnum_x_y_minnum_y(
681; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])
682; CHECK-NEXT:    ret float [[A]]
683;
684  %a = call float @llvm.minnum.f32(float %x, float %y)
685  %b = call float @llvm.minnum.f32(float %a, float %y)
686  ret float %b
687}
688
689; negative test
690
691define float @minnum_z_minnum_x_y(float %x, float %y, float %z) {
692; CHECK-LABEL: @minnum_z_minnum_x_y(
693; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])
694; CHECK-NEXT:    [[B:%.*]] = call float @llvm.minnum.f32(float [[Z:%.*]], float [[A]])
695; CHECK-NEXT:    ret float [[B]]
696;
697  %a = call float @llvm.minnum.f32(float %x, float %y)
698  %b = call float @llvm.minnum.f32(float %z, float %a)
699  ret float %b
700}
701
702; negative test
703
704define float @minnum_x_y_minnum_z(float %x, float %y, float %z) {
705; CHECK-LABEL: @minnum_x_y_minnum_z(
706; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])
707; CHECK-NEXT:    [[B:%.*]] = call float @llvm.minnum.f32(float [[A]], float [[Z:%.*]])
708; CHECK-NEXT:    ret float [[B]]
709;
710  %a = call float @llvm.minnum.f32(float %x, float %y)
711  %b = call float @llvm.minnum.f32(float %a, float %z)
712  ret float %b
713}
714
715; minnum(X, -INF) --> -INF
716
717define float @minnum_neginf(float %x) {
718; CHECK-LABEL: @minnum_neginf(
719; CHECK-NEXT:    ret float 0xFFF0000000000000
720;
721  %val = call float @llvm.minnum.f32(float %x, float 0xFFF0000000000000)
722  ret float %val
723}
724
725define <2 x double> @minnum_neginf_commute_vec(<2 x double> %x) {
726; CHECK-LABEL: @minnum_neginf_commute_vec(
727; CHECK-NEXT:    ret <2 x double> <double 0xFFF0000000000000, double 0xFFF0000000000000>
728;
729  %r = call <2 x double> @llvm.minnum.v2f64(<2 x double> <double 0xFFF0000000000000, double 0xFFF0000000000000>, <2 x double> %x)
730  ret <2 x double> %r
731}
732
733; negative test
734
735define float @minnum_inf(float %x) {
736; CHECK-LABEL: @minnum_inf(
737; CHECK-NEXT:    [[VAL:%.*]] = call float @llvm.minnum.f32(float 0x7FF0000000000000, float [[X:%.*]])
738; CHECK-NEXT:    ret float [[VAL]]
739;
740  %val = call float @llvm.minnum.f32(float 0x7FF0000000000000, float %x)
741  ret float %val
742}
743define float @maxnum_x_maxnum_x_y(float %x, float %y) {
744; CHECK-LABEL: @maxnum_x_maxnum_x_y(
745; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])
746; CHECK-NEXT:    ret float [[A]]
747;
748  %a = call float @llvm.maxnum.f32(float %x, float %y)
749  %b = call float @llvm.maxnum.f32(float %x, float %a)
750  ret float %b
751}
752
753define float @maxnum_y_maxnum_x_y(float %x, float %y) {
754; CHECK-LABEL: @maxnum_y_maxnum_x_y(
755; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])
756; CHECK-NEXT:    ret float [[A]]
757;
758  %a = call float @llvm.maxnum.f32(float %x, float %y)
759  %b = call float @llvm.maxnum.f32(float %y, float %a)
760  ret float %b
761}
762
763define float @maxnum_x_y_maxnum_x(float %x, float %y) {
764; CHECK-LABEL: @maxnum_x_y_maxnum_x(
765; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])
766; CHECK-NEXT:    ret float [[A]]
767;
768  %a = call float @llvm.maxnum.f32(float %x, float %y)
769  %b = call float @llvm.maxnum.f32(float %a, float %x)
770  ret float %b
771}
772
773define float @maxnum_x_y_maxnum_y(float %x, float %y) {
774; CHECK-LABEL: @maxnum_x_y_maxnum_y(
775; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])
776; CHECK-NEXT:    ret float [[A]]
777;
778  %a = call float @llvm.maxnum.f32(float %x, float %y)
779  %b = call float @llvm.maxnum.f32(float %a, float %y)
780  ret float %b
781}
782
783; negative test
784
785define float @maxnum_z_maxnum_x_y(float %x, float %y, float %z) {
786; CHECK-LABEL: @maxnum_z_maxnum_x_y(
787; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])
788; CHECK-NEXT:    [[B:%.*]] = call float @llvm.maxnum.f32(float [[Z:%.*]], float [[A]])
789; CHECK-NEXT:    ret float [[B]]
790;
791  %a = call float @llvm.maxnum.f32(float %x, float %y)
792  %b = call float @llvm.maxnum.f32(float %z, float %a)
793  ret float %b
794}
795
796; negative test
797
798define float @maxnum_x_y_maxnum_z(float %x, float %y, float %z) {
799; CHECK-LABEL: @maxnum_x_y_maxnum_z(
800; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])
801; CHECK-NEXT:    [[B:%.*]] = call float @llvm.maxnum.f32(float [[A]], float [[Z:%.*]])
802; CHECK-NEXT:    ret float [[B]]
803;
804  %a = call float @llvm.maxnum.f32(float %x, float %y)
805  %b = call float @llvm.maxnum.f32(float %a, float %z)
806  ret float %b
807}
808
809; maxnum(X, INF) --> INF
810
811define <2 x double> @maxnum_inf(<2 x double> %x) {
812; CHECK-LABEL: @maxnum_inf(
813; CHECK-NEXT:    ret <2 x double> <double 0x7FF0000000000000, double 0x7FF0000000000000>
814;
815  %val = call <2 x double> @llvm.maxnum.v2f64(<2 x double> %x, <2 x double><double 0x7FF0000000000000, double 0x7FF0000000000000>)
816  ret <2 x double> %val
817}
818
819define float @maxnum_inf_commute(float %x) {
820; CHECK-LABEL: @maxnum_inf_commute(
821; CHECK-NEXT:    ret float 0x7FF0000000000000
822;
823  %val = call float @llvm.maxnum.f32(float 0x7FF0000000000000, float %x)
824  ret float %val
825}
826
827; negative test
828
829define float @maxnum_neginf(float %x) {
830; CHECK-LABEL: @maxnum_neginf(
831; CHECK-NEXT:    [[VAL:%.*]] = call float @llvm.maxnum.f32(float 0xFFF0000000000000, float [[X:%.*]])
832; CHECK-NEXT:    ret float [[VAL]]
833;
834  %val = call float @llvm.maxnum.f32(float 0xFFF0000000000000, float %x)
835  ret float %val
836}
837
838; From the LangRef for minimum/maximum:
839; "If either operand is a NaN, returns NaN."
840
841define double @maximum_nan_op0(double %x) {
842; CHECK-LABEL: @maximum_nan_op0(
843; CHECK-NEXT:    ret double 0x7FF8000000000000
844;
845  %r = call double @llvm.maximum.f64(double 0x7ff8000000000000, double %x)
846  ret double %r
847}
848
849define double @maximum_nan_op1(double %x) {
850; CHECK-LABEL: @maximum_nan_op1(
851; CHECK-NEXT:    ret double 0x7FF800000000DEAD
852;
853  %r = call double @llvm.maximum.f64(double %x, double 0x7ff800000000dead)
854  ret double %r
855}
856
857define double @minimum_nan_op0(double %x) {
858; CHECK-LABEL: @minimum_nan_op0(
859; CHECK-NEXT:    ret double 0x7FF8000DEAD00000
860;
861  %r = call double @llvm.minimum.f64(double 0x7ff8000dead00000, double %x)
862  ret double %r
863}
864
865define double @minimum_nan_op1(double %x) {
866; CHECK-LABEL: @minimum_nan_op1(
867; CHECK-NEXT:    ret double 0x7FF800DEAD00DEAD
868;
869  %r = call double @llvm.minimum.f64(double %x, double 0x7ff800dead00dead)
870  ret double %r
871}
872
873define <2 x double> @maximum_nan_op0_vec_partial_undef(<2 x double> %x) {
874; CHECK-LABEL: @maximum_nan_op0_vec_partial_undef(
875; CHECK-NEXT:    ret <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>
876;
877  %r = call <2 x double> @llvm.maximum.v2f64(<2 x double> <double 0x7ff8000000000000, double undef>, <2 x double> %x)
878  ret <2 x double> %r
879}
880
881define <2 x double> @maximum_nan_op1_vec_partial_undef(<2 x double> %x) {
882; CHECK-LABEL: @maximum_nan_op1_vec_partial_undef(
883; CHECK-NEXT:    ret <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>
884;
885  %r = call <2 x double> @llvm.maximum.v2f64(<2 x double> %x, <2 x double> <double 0x7ff8000000000000, double undef>)
886  ret <2 x double> %r
887}
888
889define <2 x double> @maximum_nan_op1_vec(<2 x double> %x) {
890; CHECK-LABEL: @maximum_nan_op1_vec(
891; CHECK-NEXT:    ret <2 x double> <double 0x7FF800000000DEAD, double 0x7FF8FFFFFFFFFFFF>
892;
893  %r = call <2 x double> @llvm.maximum.v2f64(<2 x double> %x, <2 x double> <double 0x7ff800000000dead, double 0x7ff8ffffffffffff>)
894  ret <2 x double> %r
895}
896
897define <2 x double> @minimum_nan_op0_vec_partial_undef(<2 x double> %x) {
898; CHECK-LABEL: @minimum_nan_op0_vec_partial_undef(
899; CHECK-NEXT:    ret <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>
900;
901  %r = call <2 x double> @llvm.minimum.v2f64(<2 x double> <double undef, double 0x7ff8000dead00000>, <2 x double> %x)
902  ret <2 x double> %r
903}
904
905define <2 x double> @minimum_nan_op1_vec_partial_undef(<2 x double> %x) {
906; CHECK-LABEL: @minimum_nan_op1_vec_partial_undef(
907; CHECK-NEXT:    ret <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000>
908;
909  %r = call <2 x double> @llvm.minimum.v2f64(<2 x double> %x, <2 x double> <double undef, double 0x7ff8000dead00000>)
910  ret <2 x double> %r
911}
912
913define <2 x double> @minimum_nan_op1_vec(<2 x double> %x) {
914; CHECK-LABEL: @minimum_nan_op1_vec(
915; CHECK-NEXT:    ret <2 x double> <double 0x7FF800DEAD00DEAD, double 0x7FF800DEAD00DEAD>
916;
917  %r = call <2 x double> @llvm.minimum.v2f64(<2 x double> %x, <2 x double> <double 0x7ff800dead00dead, double 0x7ff800dead00dead>)
918  ret <2 x double> %r
919}
920
921define float @maximum_undef_op1(float %x) {
922; CHECK-LABEL: @maximum_undef_op1(
923; CHECK-NEXT:    ret float [[X:%.*]]
924;
925  %val = call float @llvm.maximum.f32(float %x, float undef)
926  ret float %val
927}
928
929define float @maximum_poison_op1(float %x) {
930; CHECK-LABEL: @maximum_poison_op1(
931; CHECK-NEXT:    ret float [[X:%.*]]
932;
933  %val = call float @llvm.maximum.f32(float %x, float poison)
934  ret float %val
935}
936
937define float @maximum_undef_op0(float %x) {
938; CHECK-LABEL: @maximum_undef_op0(
939; CHECK-NEXT:    ret float [[X:%.*]]
940;
941  %val = call float @llvm.maximum.f32(float undef, float %x)
942  ret float %val
943}
944
945define float @maximum_poison_op0(float %x) {
946; CHECK-LABEL: @maximum_poison_op0(
947; CHECK-NEXT:    ret float [[X:%.*]]
948;
949  %val = call float @llvm.maximum.f32(float poison, float %x)
950  ret float %val
951}
952
953define float @minimum_undef_op1(float %x) {
954; CHECK-LABEL: @minimum_undef_op1(
955; CHECK-NEXT:    ret float [[X:%.*]]
956;
957  %val = call float @llvm.minimum.f32(float %x, float undef)
958  ret float %val
959}
960
961define float @minimum_poison_op1(float %x) {
962; CHECK-LABEL: @minimum_poison_op1(
963; CHECK-NEXT:    ret float [[X:%.*]]
964;
965  %val = call float @llvm.minimum.f32(float %x, float poison)
966  ret float %val
967}
968
969define float @minimum_undef_op0(float %x) {
970; CHECK-LABEL: @minimum_undef_op0(
971; CHECK-NEXT:    ret float [[X:%.*]]
972;
973  %val = call float @llvm.minimum.f32(float undef, float %x)
974  ret float %val
975}
976
977define float @minimum_poison_op0(float %x) {
978; CHECK-LABEL: @minimum_poison_op0(
979; CHECK-NEXT:    ret float [[X:%.*]]
980;
981  %val = call float @llvm.minimum.f32(float poison, float %x)
982  ret float %val
983}
984
985define float @minimum_undef_undef(float %x) {
986; CHECK-LABEL: @minimum_undef_undef(
987; CHECK-NEXT:    ret float undef
988;
989  %val = call float @llvm.minimum.f32(float undef, float undef)
990  ret float %val
991}
992
993define float @maximum_undef_undef(float %x) {
994; CHECK-LABEL: @maximum_undef_undef(
995; CHECK-NEXT:    ret float undef
996;
997  %val = call float @llvm.maximum.f32(float undef, float undef)
998  ret float %val
999}
1000
1001define float @minimum_same_args(float %x) {
1002; CHECK-LABEL: @minimum_same_args(
1003; CHECK-NEXT:    ret float [[X:%.*]]
1004;
1005  %y = call float @llvm.minimum.f32(float %x, float %x)
1006  ret float %y
1007}
1008
1009define float @maximum_same_args(float %x) {
1010; CHECK-LABEL: @maximum_same_args(
1011; CHECK-NEXT:    ret float [[X:%.*]]
1012;
1013  %y = call float @llvm.maximum.f32(float %x, float %x)
1014  ret float %y
1015}
1016
1017define float @minimum_x_minimum_x_y(float %x, float %y) {
1018; CHECK-LABEL: @minimum_x_minimum_x_y(
1019; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float [[Y:%.*]])
1020; CHECK-NEXT:    ret float [[A]]
1021;
1022  %a = call float @llvm.minimum.f32(float %x, float %y)
1023  %b = call float @llvm.minimum.f32(float %x, float %a)
1024  ret float %b
1025}
1026
1027define float @minimum_y_minimum_x_y(float %x, float %y) {
1028; CHECK-LABEL: @minimum_y_minimum_x_y(
1029; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float [[Y:%.*]])
1030; CHECK-NEXT:    ret float [[A]]
1031;
1032  %a = call float @llvm.minimum.f32(float %x, float %y)
1033  %b = call float @llvm.minimum.f32(float %y, float %a)
1034  ret float %b
1035}
1036
1037define float @minimum_x_y_minimum_x(float %x, float %y) {
1038; CHECK-LABEL: @minimum_x_y_minimum_x(
1039; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float [[Y:%.*]])
1040; CHECK-NEXT:    ret float [[A]]
1041;
1042  %a = call float @llvm.minimum.f32(float %x, float %y)
1043  %b = call float @llvm.minimum.f32(float %a, float %x)
1044  ret float %b
1045}
1046
1047define float @minimum_x_y_minimum_y(float %x, float %y) {
1048; CHECK-LABEL: @minimum_x_y_minimum_y(
1049; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float [[Y:%.*]])
1050; CHECK-NEXT:    ret float [[A]]
1051;
1052  %a = call float @llvm.minimum.f32(float %x, float %y)
1053  %b = call float @llvm.minimum.f32(float %a, float %y)
1054  ret float %b
1055}
1056
1057; negative test
1058
1059define float @minimum_z_minimum_x_y(float %x, float %y, float %z) {
1060; CHECK-LABEL: @minimum_z_minimum_x_y(
1061; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float [[Y:%.*]])
1062; CHECK-NEXT:    [[B:%.*]] = call float @llvm.minimum.f32(float [[Z:%.*]], float [[A]])
1063; CHECK-NEXT:    ret float [[B]]
1064;
1065  %a = call float @llvm.minimum.f32(float %x, float %y)
1066  %b = call float @llvm.minimum.f32(float %z, float %a)
1067  ret float %b
1068}
1069
1070; negative test
1071
1072define float @minimum_x_y_minimum_z(float %x, float %y, float %z) {
1073; CHECK-LABEL: @minimum_x_y_minimum_z(
1074; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float [[Y:%.*]])
1075; CHECK-NEXT:    [[B:%.*]] = call float @llvm.minimum.f32(float [[A]], float [[Z:%.*]])
1076; CHECK-NEXT:    ret float [[B]]
1077;
1078  %a = call float @llvm.minimum.f32(float %x, float %y)
1079  %b = call float @llvm.minimum.f32(float %a, float %z)
1080  ret float %b
1081}
1082
1083define float @maximum_x_maximum_x_y(float %x, float %y) {
1084; CHECK-LABEL: @maximum_x_maximum_x_y(
1085; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float [[Y:%.*]])
1086; CHECK-NEXT:    ret float [[A]]
1087;
1088  %a = call float @llvm.maximum.f32(float %x, float %y)
1089  %b = call float @llvm.maximum.f32(float %x, float %a)
1090  ret float %b
1091}
1092
1093define float @maximum_y_maximum_x_y(float %x, float %y) {
1094; CHECK-LABEL: @maximum_y_maximum_x_y(
1095; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float [[Y:%.*]])
1096; CHECK-NEXT:    ret float [[A]]
1097;
1098  %a = call float @llvm.maximum.f32(float %x, float %y)
1099  %b = call float @llvm.maximum.f32(float %y, float %a)
1100  ret float %b
1101}
1102
1103define float @maximum_x_y_maximum_x(float %x, float %y) {
1104; CHECK-LABEL: @maximum_x_y_maximum_x(
1105; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float [[Y:%.*]])
1106; CHECK-NEXT:    ret float [[A]]
1107;
1108  %a = call float @llvm.maximum.f32(float %x, float %y)
1109  %b = call float @llvm.maximum.f32(float %a, float %x)
1110  ret float %b
1111}
1112
1113define float @maximum_x_y_maximum_y(float %x, float %y) {
1114; CHECK-LABEL: @maximum_x_y_maximum_y(
1115; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float [[Y:%.*]])
1116; CHECK-NEXT:    ret float [[A]]
1117;
1118  %a = call float @llvm.maximum.f32(float %x, float %y)
1119  %b = call float @llvm.maximum.f32(float %a, float %y)
1120  ret float %b
1121}
1122
1123; negative test
1124
1125define float @maximum_z_maximum_x_y(float %x, float %y, float %z) {
1126; CHECK-LABEL: @maximum_z_maximum_x_y(
1127; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float [[Y:%.*]])
1128; CHECK-NEXT:    [[B:%.*]] = call float @llvm.maximum.f32(float [[Z:%.*]], float [[A]])
1129; CHECK-NEXT:    ret float [[B]]
1130;
1131  %a = call float @llvm.maximum.f32(float %x, float %y)
1132  %b = call float @llvm.maximum.f32(float %z, float %a)
1133  ret float %b
1134}
1135
1136; negative test
1137
1138define float @maximum_x_y_maximum_z(float %x, float %y, float %z) {
1139; CHECK-LABEL: @maximum_x_y_maximum_z(
1140; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maximum.f32(float [[X:%.*]], float [[Y:%.*]])
1141; CHECK-NEXT:    [[B:%.*]] = call float @llvm.maximum.f32(float [[A]], float [[Z:%.*]])
1142; CHECK-NEXT:    ret float [[B]]
1143;
1144  %a = call float @llvm.maximum.f32(float %x, float %y)
1145  %b = call float @llvm.maximum.f32(float %a, float %z)
1146  ret float %b
1147}
1148
1149; negative test - minimum(X, -INF) != -INF because X could be NaN
1150
1151define float @minimum_neginf(float %x) {
1152; CHECK-LABEL: @minimum_neginf(
1153; CHECK-NEXT:    [[VAL:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float 0xFFF0000000000000)
1154; CHECK-NEXT:    ret float [[VAL]]
1155;
1156  %val = call float @llvm.minimum.f32(float %x, float 0xFFF0000000000000)
1157  ret float %val
1158}
1159
1160; negative test - minimum(-INF, X) != -INF because X could be NaN
1161
1162define <2 x double> @minimum_neginf_commute_vec(<2 x double> %x) {
1163; CHECK-LABEL: @minimum_neginf_commute_vec(
1164; CHECK-NEXT:    [[R:%.*]] = call <2 x double> @llvm.minimum.v2f64(<2 x double> <double 0xFFF0000000000000, double 0xFFF0000000000000>, <2 x double> [[X:%.*]])
1165; CHECK-NEXT:    ret <2 x double> [[R]]
1166;
1167  %r = call <2 x double> @llvm.minimum.v2f64(<2 x double> <double 0xFFF0000000000000, double 0xFFF0000000000000>, <2 x double> %x)
1168  ret <2 x double> %r
1169}
1170
1171; TODO: minimum(INF, X) --> X
1172
1173define float @minimum_inf(float %x) {
1174; CHECK-LABEL: @minimum_inf(
1175; CHECK-NEXT:    ret float [[X:%.*]]
1176;
1177  %val = call float @llvm.minimum.f32(float 0x7FF0000000000000, float %x)
1178  ret float %val
1179}
1180
1181; negative test - maximum(X, INF) != INF because X could be NaN
1182
1183define <2 x double> @maximum_inf(<2 x double> %x) {
1184; CHECK-LABEL: @maximum_inf(
1185; CHECK-NEXT:    [[VAL:%.*]] = call <2 x double> @llvm.maximum.v2f64(<2 x double> [[X:%.*]], <2 x double> <double 0x7FF0000000000000, double 0x7FF0000000000000>)
1186; CHECK-NEXT:    ret <2 x double> [[VAL]]
1187;
1188  %val = call <2 x double> @llvm.maximum.v2f64(<2 x double> %x, <2 x double><double 0x7FF0000000000000, double 0x7FF0000000000000>)
1189  ret <2 x double> %val
1190}
1191
1192; negative test - maximum(INF, X) != INF because X could be NaN
1193
1194define float @maximum_inf_commute(float %x) {
1195; CHECK-LABEL: @maximum_inf_commute(
1196; CHECK-NEXT:    [[VAL:%.*]] = call float @llvm.maximum.f32(float 0x7FF0000000000000, float [[X:%.*]])
1197; CHECK-NEXT:    ret float [[VAL]]
1198;
1199  %val = call float @llvm.maximum.f32(float 0x7FF0000000000000, float %x)
1200  ret float %val
1201}
1202