fbe41d035d4c431820da659c2ccfd5f9339db6ef
[oota-llvm.git] / test / CodeGen / X86 / fmaxnum.ll
1 ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=sse2  < %s | FileCheck %s --check-prefix=CHECK --check-prefix=SSE
2 ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=avx  < %s | FileCheck %s --check-prefix=CHECK --check-prefix=AVX
3
4 declare float @fmaxf(float, float)
5 declare double @fmax(double, double)
6 declare x86_fp80 @fmaxl(x86_fp80, x86_fp80)
7 declare float @llvm.maxnum.f32(float, float)
8 declare double @llvm.maxnum.f64(double, double)
9 declare x86_fp80 @llvm.maxnum.f80(x86_fp80, x86_fp80)
10
11 declare <2 x float> @llvm.maxnum.v2f32(<2 x float>, <2 x float>)
12 declare <4 x float> @llvm.maxnum.v4f32(<4 x float>, <4 x float>)
13 declare <2 x double> @llvm.maxnum.v2f64(<2 x double>, <2 x double>)
14 declare <4 x double> @llvm.maxnum.v4f64(<4 x double>, <4 x double>)
15 declare <8 x double> @llvm.maxnum.v8f64(<8 x double>, <8 x double>)
16
17
18 ; CHECK-LABEL: @test_fmaxf
19 ; SSE:         movaps %xmm0, %xmm2
20 ; SSE-NEXT:    cmpunordss %xmm2, %xmm2
21 ; SSE-NEXT:    movaps %xmm2, %xmm3
22 ; SSE-NEXT:    andps %xmm1, %xmm3
23 ; SSE-NEXT:    maxss %xmm0, %xmm1
24 ; SSE-NEXT:    andnps %xmm1, %xmm2
25 ; SSE-NEXT:    orps %xmm3, %xmm2
26 ; SSE-NEXT:    movaps %xmm2, %xmm0
27 ; SSE-NEXT:    retq
28 ;
29 ; AVX:         vmaxss %xmm0, %xmm1, %xmm2
30 ; AVX-NEXT:    vcmpunordss %xmm0, %xmm0, %xmm0
31 ; AVX-NEXT:    vblendvps %xmm0, %xmm1, %xmm2, %xmm0
32 ; AVX-NEXT:    retq
33 define float @test_fmaxf(float %x, float %y) {
34   %z = call float @fmaxf(float %x, float %y) readnone
35   ret float %z
36 }
37
38 ; CHECK-LABEL: @test_fmaxf_minsize
39 ; CHECK:       jmp fmaxf
40 define float @test_fmaxf_minsize(float %x, float %y) minsize {
41   %z = call float @fmaxf(float %x, float %y) readnone
42   ret float %z
43 }
44
45 ; FIXME: Doubles should be inlined similarly to floats.
46
47 ; CHECK-LABEL: @test_fmax
48 ; CHECK: jmp fmax
49 define double @test_fmax(double %x, double %y) {
50   %z = call double @fmax(double %x, double %y) readnone
51   ret double %z
52 }
53
54 ; CHECK-LABEL: @test_fmaxl
55 ; CHECK: callq fmaxl
56 define x86_fp80 @test_fmaxl(x86_fp80 %x, x86_fp80 %y) {
57   %z = call x86_fp80 @fmaxl(x86_fp80 %x, x86_fp80 %y) readnone
58   ret x86_fp80 %z
59 }
60
61 ; CHECK-LABEL: @test_intrinsic_fmaxf
62 ; SSE:         movaps %xmm0, %xmm2
63 ; SSE-NEXT:    cmpunordss %xmm2, %xmm2
64 ; SSE-NEXT:    movaps %xmm2, %xmm3
65 ; SSE-NEXT:    andps %xmm1, %xmm3
66 ; SSE-NEXT:    maxss %xmm0, %xmm1
67 ; SSE-NEXT:    andnps %xmm1, %xmm2
68 ; SSE-NEXT:    orps %xmm3, %xmm2
69 ; SSE-NEXT:    movaps %xmm2, %xmm0
70 ; SSE-NEXT:    retq
71 ;
72 ; AVX:         vmaxss %xmm0, %xmm1, %xmm2
73 ; AVX-NEXT:    vcmpunordss %xmm0, %xmm0, %xmm0
74 ; AVX-NEXT:    vblendvps %xmm0, %xmm1, %xmm2, %xmm0
75 ; AVX-NEXT:    retq
76 define float @test_intrinsic_fmaxf(float %x, float %y) {
77   %z = call float @llvm.maxnum.f32(float %x, float %y) readnone
78   ret float %z
79 }
80
81 ; FIXME: Doubles should be inlined similarly to floats.
82
83 ; CHECK-LABEL: @test_intrinsic_fmax
84 ; CHECK: jmp fmax
85 define double @test_intrinsic_fmax(double %x, double %y) {
86   %z = call double @llvm.maxnum.f64(double %x, double %y) readnone
87   ret double %z
88 }
89
90 ; CHECK-LABEL: @test_intrinsic_fmaxl
91 ; CHECK: callq fmaxl
92 define x86_fp80 @test_intrinsic_fmaxl(x86_fp80 %x, x86_fp80 %y) {
93   %z = call x86_fp80 @llvm.maxnum.f80(x86_fp80 %x, x86_fp80 %y) readnone
94   ret x86_fp80 %z
95 }
96
97 ; CHECK-LABEL: @test_intrinsic_fmax_v2f32
98 ; SSE:         movaps %xmm1, %xmm2
99 ; SSE-NEXT:    maxps %xmm0, %xmm2
100 ; SSE-NEXT:    cmpunordps %xmm0, %xmm0
101 ; SSE-NEXT:    andps %xmm0, %xmm1
102 ; SSE-NEXT:    andnps %xmm2, %xmm0
103 ; SSE-NEXT:    orps %xmm1, %xmm0
104 ; SSE-NEXT:    retq
105 ;
106 ; AVX:         vmaxps %xmm0, %xmm1, %xmm2
107 ; AVX-NEXT:    vcmpunordps %xmm0, %xmm0, %xmm0
108 ; AVX-NEXT:    vblendvps %xmm0, %xmm1, %xmm2, %xmm0
109 ; AVX-NEXT:    retq
110 define <2 x float> @test_intrinsic_fmax_v2f32(<2 x float> %x, <2 x float> %y) {
111   %z = call <2 x float> @llvm.maxnum.v2f32(<2 x float> %x, <2 x float> %y) readnone
112   ret <2 x float> %z
113 }
114
115 ; CHECK-LABEL: @test_intrinsic_fmax_v4f32
116 ; SSE:         movaps %xmm1, %xmm2
117 ; SSE-NEXT:    maxps %xmm0, %xmm2
118 ; SSE-NEXT:    cmpunordps %xmm0, %xmm0
119 ; SSE-NEXT:    andps %xmm0, %xmm1
120 ; SSE-NEXT:    andnps %xmm2, %xmm0
121 ; SSE-NEXT:    orps %xmm1, %xmm0
122 ; SSE-NEXT:    retq
123 ;
124 ; AVX:         vmaxps %xmm0, %xmm1, %xmm2
125 ; AVX-NEXT:    vcmpunordps %xmm0, %xmm0, %xmm0
126 ; AVX-NEXT:    vblendvps %xmm0, %xmm1, %xmm2, %xmm0
127 ; AVX-NEXT:    retq
128 define <4 x float> @test_intrinsic_fmax_v4f32(<4 x float> %x, <4 x float> %y) {
129   %z = call <4 x float> @llvm.maxnum.v4f32(<4 x float> %x, <4 x float> %y) readnone
130   ret <4 x float> %z
131 }
132
133 ; FIXME: Vector of doubles should be inlined similarly to vector of floats.
134
135 ; CHECK-LABEL: @test_intrinsic_fmax_v2f64
136 ; CHECK: callq fmax
137 ; CHECK: callq fmax
138 define <2 x double> @test_intrinsic_fmax_v2f64(<2 x double> %x, <2 x double> %y) {
139   %z = call <2 x double> @llvm.maxnum.v2f64(<2 x double> %x, <2 x double> %y) readnone
140   ret <2 x double> %z
141 }
142
143 ; FIXME: Vector of doubles should be inlined similarly to vector of floats.
144
145 ; CHECK-LABEL: @test_intrinsic_fmax_v4f64
146 ; CHECK: callq fmax
147 ; CHECK: callq fmax
148 ; CHECK: callq fmax
149 ; CHECK: callq fmax
150 define <4 x double> @test_intrinsic_fmax_v4f64(<4 x double> %x, <4 x double> %y) {
151   %z = call <4 x double> @llvm.maxnum.v4f64(<4 x double> %x, <4 x double> %y) readnone
152   ret <4 x double> %z
153 }
154
155 ; FIXME: Vector of doubles should be inlined similarly to vector of floats.
156
157 ; CHECK-LABEL: @test_intrinsic_fmax_v8f64
158 ; CHECK: callq fmax
159 ; CHECK: callq fmax
160 ; CHECK: callq fmax
161 ; CHECK: callq fmax
162 ; CHECK: callq fmax
163 ; CHECK: callq fmax
164 ; CHECK: callq fmax
165 ; CHECK: callq fmax
166 define <8 x double> @test_intrinsic_fmax_v8f64(<8 x double> %x, <8 x double> %y) {
167   %z = call <8 x double> @llvm.maxnum.v8f64(<8 x double> %x, <8 x double> %y) readnone
168   ret <8 x double> %z
169 }
170