The X86 backend has a number of optimizations for SETCC nodes which use
[oota-llvm.git] / test / CodeGen / X86 / fma_patterns.ll
1 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=core-avx2 -mattr=avx2,+fma -fp-contract=fast | FileCheck %s
2
3 ; CHECK: test_x86_fmadd_ps
4 ; CHECK: vfmadd213ps     %xmm2, %xmm0, %xmm1
5 ; CHECK: ret
6 define <4 x float> @test_x86_fmadd_ps(<4 x float> %a0, <4 x float> %a1, <4 x float> %a2) {
7   %x = fmul <4 x float> %a0, %a1
8   %res = fadd <4 x float> %x, %a2
9   ret <4 x float> %res
10 }
11
12 ; CHECK: test_x86_fmsub_ps
13 ; CHECK: fmsub213ps     %xmm2, %xmm0, %xmm1
14 ; CHECK: ret
15 define <4 x float> @test_x86_fmsub_ps(<4 x float> %a0, <4 x float> %a1, <4 x float> %a2) {
16   %x = fmul <4 x float> %a0, %a1
17   %res = fsub <4 x float> %x, %a2
18   ret <4 x float> %res
19 }
20
21 ; CHECK: test_x86_fnmadd_ps
22 ; CHECK: fnmadd213ps     %xmm2, %xmm0, %xmm1
23 ; CHECK: ret
24 define <4 x float> @test_x86_fnmadd_ps(<4 x float> %a0, <4 x float> %a1, <4 x float> %a2) {
25   %x = fmul <4 x float> %a0, %a1
26   %res = fsub <4 x float> %a2, %x
27   ret <4 x float> %res
28 }
29
30 ; CHECK: test_x86_fnmsub_ps
31 ; CHECK: fnmsub213ps     %xmm2, %xmm0, %xmm1
32 ; CHECK: ret
33 define <4 x float> @test_x86_fnmsub_ps(<4 x float> %a0, <4 x float> %a1, <4 x float> %a2) {
34   %x = fmul <4 x float> %a0, %a1
35   %y = fsub <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %x
36   %res = fsub <4 x float> %y, %a2
37   ret <4 x float> %res
38 }
39
40 ; CHECK: test_x86_fmadd_ps_y
41 ; CHECK: vfmadd213ps     %ymm2, %ymm0, %ymm1
42 ; CHECK: ret
43 define <8 x float> @test_x86_fmadd_ps_y(<8 x float> %a0, <8 x float> %a1, <8 x float> %a2) {
44   %x = fmul <8 x float> %a0, %a1
45   %res = fadd <8 x float> %x, %a2
46   ret <8 x float> %res
47 }
48
49 ; CHECK: test_x86_fmsub_ps_y
50 ; CHECK: vfmsub213ps     %ymm2, %ymm0, %ymm1
51 ; CHECK: ret
52 define <8 x float> @test_x86_fmsub_ps_y(<8 x float> %a0, <8 x float> %a1, <8 x float> %a2) {
53   %x = fmul <8 x float> %a0, %a1
54   %res = fsub <8 x float> %x, %a2
55   ret <8 x float> %res
56 }
57
58 ; CHECK: test_x86_fnmadd_ps_y
59 ; CHECK: vfnmadd213ps     %ymm2, %ymm0, %ymm1
60 ; CHECK: ret
61 define <8 x float> @test_x86_fnmadd_ps_y(<8 x float> %a0, <8 x float> %a1, <8 x float> %a2) {
62   %x = fmul <8 x float> %a0, %a1
63   %res = fsub <8 x float> %a2, %x
64   ret <8 x float> %res
65 }
66
67 ; CHECK: test_x86_fnmsub_ps_y
68 ; CHECK: vfnmsub213ps     %ymm2, %ymm0, %ymm1
69 ; CHECK: ret
70 define <8 x float> @test_x86_fnmsub_ps_y(<8 x float> %a0, <8 x float> %a1, <8 x float> %a2) {
71   %x = fmul <8 x float> %a0, %a1
72   %y = fsub <8 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %x
73   %res = fsub <8 x float> %y, %a2
74   ret <8 x float> %res
75 }
76
77 ; CHECK: test_x86_fmadd_pd_y
78 ; CHECK: vfmadd213pd     %ymm2, %ymm0, %ymm1
79 ; CHECK: ret
80 define <4 x double> @test_x86_fmadd_pd_y(<4 x double> %a0, <4 x double> %a1, <4 x double> %a2) {
81   %x = fmul <4 x double> %a0, %a1
82   %res = fadd <4 x double> %x, %a2
83   ret <4 x double> %res
84 }
85
86 ; CHECK: test_x86_fmsub_pd_y
87 ; CHECK: vfmsub213pd     %ymm2, %ymm0, %ymm1
88 ; CHECK: ret
89 define <4 x double> @test_x86_fmsub_pd_y(<4 x double> %a0, <4 x double> %a1, <4 x double> %a2) {
90   %x = fmul <4 x double> %a0, %a1
91   %res = fsub <4 x double> %x, %a2
92   ret <4 x double> %res
93 }
94
95 ; CHECK: test_x86_fmsub_pd
96 ; CHECK: vfmsub213pd     %xmm2, %xmm0, %xmm1
97 ; CHECK: ret
98 define <2 x double> @test_x86_fmsub_pd(<2 x double> %a0, <2 x double> %a1, <2 x double> %a2) {
99   %x = fmul <2 x double> %a0, %a1
100   %res = fsub <2 x double> %x, %a2
101   ret <2 x double> %res
102 }
103
104 ; CHECK: test_x86_fnmadd_ss
105 ; CHECK: vfnmadd213ss    %xmm2, %xmm0, %xmm1
106 ; CHECK: ret
107 define float @test_x86_fnmadd_ss(float %a0, float %a1, float %a2) {
108   %x = fmul float %a0, %a1
109   %res = fsub float %a2, %x
110   ret float %res
111 }
112
113 ; CHECK: test_x86_fnmadd_sd
114 ; CHECK: vfnmadd213sd     %xmm2, %xmm0, %xmm1
115 ; CHECK: ret
116 define double @test_x86_fnmadd_sd(double %a0, double %a1, double %a2) {
117   %x = fmul double %a0, %a1
118   %res = fsub double %a2, %x
119   ret double %res
120 }
121
122 ; CHECK: test_x86_fmsub_sd
123 ; CHECK: vfmsub213sd     %xmm2, %xmm0, %xmm1
124 ; CHECK: ret
125 define double @test_x86_fmsub_sd(double %a0, double %a1, double %a2) {
126   %x = fmul double %a0, %a1
127   %res = fsub double %x, %a2
128   ret double %res
129 }
130
131 ; CHECK: test_x86_fnmsub_ss
132 ; CHECK: vfnmsub213ss     %xmm2, %xmm0, %xmm1
133 ; CHECK: ret
134 define float @test_x86_fnmsub_ss(float %a0, float %a1, float %a2) {
135   %x = fsub float -0.000000e+00, %a0
136   %y = fmul float %x, %a1
137   %res = fsub float %y, %a2
138   ret float %res
139 }