1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+avx2,+fma | FileCheck %s --check-prefixes=CHECK,X86
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2,+fma | FileCheck %s --check-prefixes=CHECK,X64
5 declare <8 x float> @llvm.fma.v8f32(<8 x float>, <8 x float>, <8 x float>)
6 declare <4 x float> @llvm.fma.v4f32(<4 x float>, <4 x float>, <4 x float>)
7 declare float @llvm.fma.f32(float, float, float)
8 declare <2 x double> @llvm.fma.v2f64(<2 x double>, <2 x double>, <2 x double>)
9 declare <4 x double> @llvm.fma.v4f64(<4 x double>, <4 x double>, <4 x double>)
11 ; This test checks combinations of FNEG and FMA intrinsics
13 define <8 x float> @test1(<8 x float> %a, <8 x float> %b, <8 x float> %c) {
16 ; CHECK-NEXT: vfmsub213ps {{.*#+}} ymm0 = (ymm1 * ymm0) - ymm2
17 ; CHECK-NEXT: ret{{[l|q]}}
18 %sub.i = fsub <8 x float> <float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0>, %c
19 %r = tail call nsz <8 x float> @llvm.fma.v8f32(<8 x float> %a, <8 x float> %b, <8 x float> %sub.i) #2
23 define <4 x float> @test2(<4 x float> %a, <4 x float> %b, <4 x float> %c) {
26 ; CHECK-NEXT: vfnmsub213ps {{.*#+}} xmm0 = -(xmm1 * xmm0) - xmm2
27 ; CHECK-NEXT: ret{{[l|q]}}
28 %t0 = tail call nsz <4 x float> @llvm.fma.v4f32(<4 x float> %a, <4 x float> %b, <4 x float> %c) #2
29 %sub.i = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %t0
30 ret <4 x float> %sub.i
33 define <4 x float> @test3(<4 x float> %a, <4 x float> %b, <4 x float> %c) {
36 ; CHECK-NEXT: vfnmadd213ss {{.*#+}} xmm0 = -(xmm1 * xmm0) + xmm2
37 ; CHECK-NEXT: vbroadcastss {{.*#+}} xmm1 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
38 ; CHECK-NEXT: vxorps %xmm1, %xmm0, %xmm0
39 ; CHECK-NEXT: ret{{[l|q]}}
40 %a0 = extractelement <4 x float> %a, i64 0
41 %b0 = extractelement <4 x float> %b, i64 0
42 %c0 = extractelement <4 x float> %c, i64 0
43 %negb0 = fneg float %b0
44 %t0 = tail call nsz float @llvm.fma.f32(float %a0, float %negb0, float %c0) #2
45 %i = insertelement <4 x float> %a, float %t0, i64 0
46 %sub.i = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %i
47 ret <4 x float> %sub.i
50 define <8 x float> @test4(<8 x float> %a, <8 x float> %b, <8 x float> %c) {
53 ; CHECK-NEXT: vfnmadd213ps {{.*#+}} ymm0 = -(ymm1 * ymm0) + ymm2
54 ; CHECK-NEXT: ret{{[l|q]}}
55 %negc = fneg <8 x float> %c
56 %t0 = tail call nsz <8 x float> @llvm.fma.v8f32(<8 x float> %a, <8 x float> %b, <8 x float> %negc) #2
57 %sub.i = fsub <8 x float> <float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0>, %t0
58 ret <8 x float> %sub.i
61 define <8 x float> @test5(<8 x float> %a, <8 x float> %b, <8 x float> %c) {
64 ; CHECK-NEXT: vfmadd213ps {{.*#+}} ymm0 = (ymm1 * ymm0) + ymm2
65 ; CHECK-NEXT: ret{{[l|q]}}
66 %sub.c = fsub <8 x float> <float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0, float -0.0>, %c
67 %negsubc = fneg <8 x float> %sub.c
68 %t0 = tail call nsz <8 x float> @llvm.fma.v8f32(<8 x float> %a, <8 x float> %b, <8 x float> %negsubc) #2
72 define <2 x double> @test6(<2 x double> %a, <2 x double> %b, <2 x double> %c) {
75 ; CHECK-NEXT: vfnmsub213pd {{.*#+}} xmm0 = -(xmm1 * xmm0) - xmm2
76 ; CHECK-NEXT: ret{{[l|q]}}
77 %t0 = tail call nsz <2 x double> @llvm.fma.v2f64(<2 x double> %a, <2 x double> %b, <2 x double> %c) #2
78 %sub.i = fsub <2 x double> <double -0.0, double -0.0>, %t0
79 ret <2 x double> %sub.i
82 define <8 x float> @test7(float %a, <8 x float> %b, <8 x float> %c) {
85 ; X86-NEXT: vbroadcastss {{[0-9]+}}(%esp), %ymm2
86 ; X86-NEXT: vfnmadd213ps {{.*#+}} ymm0 = -(ymm2 * ymm0) + ymm1
91 ; X64-NEXT: vbroadcastss %xmm0, %ymm0
92 ; X64-NEXT: vfnmadd213ps {{.*#+}} ymm0 = -(ymm1 * ymm0) + ymm2
94 %t0 = insertelement <8 x float> undef, float %a, i32 0
95 %t1 = fsub <8 x float> <float -0.0, float undef, float undef, float undef, float undef, float undef, float undef, float undef>, %t0
96 %t2 = shufflevector <8 x float> %t1, <8 x float> undef, <8 x i32> zeroinitializer
97 %t3 = tail call nsz <8 x float> @llvm.fma.v8f32(<8 x float> %t2, <8 x float> %b, <8 x float> %c)
102 define <8 x float> @test8(float %a, <8 x float> %b, <8 x float> %c) {
105 ; X86-NEXT: vbroadcastss {{[0-9]+}}(%esp), %ymm2
106 ; X86-NEXT: vfnmadd213ps {{.*#+}} ymm0 = -(ymm2 * ymm0) + ymm1
111 ; X64-NEXT: vbroadcastss %xmm0, %ymm0
112 ; X64-NEXT: vfnmadd213ps {{.*#+}} ymm0 = -(ymm1 * ymm0) + ymm2
114 %t0 = fsub float -0.0, %a
115 %t1 = insertelement <8 x float> undef, float %t0, i32 0
116 %t2 = shufflevector <8 x float> %t1, <8 x float> undef, <8 x i32> zeroinitializer
117 %t3 = tail call nsz <8 x float> @llvm.fma.v8f32(<8 x float> %t2, <8 x float> %b, <8 x float> %c)
121 define <4 x double> @test9(<4 x double> %a) {
122 ; CHECK-LABEL: test9:
124 ; CHECK-NEXT: vbroadcastsd {{.*#+}} ymm1 = [-5.0E-1,-5.0E-1,-5.0E-1,-5.0E-1]
125 ; CHECK-NEXT: vfnmadd213pd {{.*#+}} ymm0 = -(ymm1 * ymm0) + ymm1
126 ; CHECK-NEXT: ret{{[l|q]}}
127 %t = tail call <4 x double> @llvm.fma.v4f64(<4 x double> %a, <4 x double> <double 5.000000e-01, double 5.000000e-01, double 5.000000e-01, double 5.000000e-01>, <4 x double> <double -5.000000e-01, double -5.000000e-01, double -5.000000e-01, double -5.000000e-01>)
131 define <4 x double> @test10(<4 x double> %a, <4 x double> %b) {
132 ; CHECK-LABEL: test10:
134 ; CHECK-NEXT: vmovapd {{.*#+}} ymm2 = [-9.5E+0,u,-5.5E+0,-2.5E+0]
135 ; CHECK-NEXT: vmovapd %ymm2, %ymm3
136 ; CHECK-NEXT: vfmadd213pd {{.*#+}} ymm3 = (ymm0 * ymm3) + ymm1
137 ; CHECK-NEXT: vfnmadd213pd {{.*#+}} ymm2 = -(ymm0 * ymm2) + ymm1
138 ; CHECK-NEXT: vaddpd %ymm2, %ymm3, %ymm0
139 ; CHECK-NEXT: ret{{[l|q]}}
140 %t0 = tail call <4 x double> @llvm.fma.v4f64(<4 x double> %a, <4 x double> <double -95.00000e-01, double undef, double -55.00000e-01, double -25.00000e-01>, <4 x double> %b)
141 %t1 = tail call <4 x double> @llvm.fma.v4f64(<4 x double> %a, <4 x double> <double 95.00000e-01, double undef, double 55.00000e-01, double 25.00000e-01>, <4 x double> %b)
142 %t2 = fadd <4 x double> %t0, %t1
146 define <4 x double> @test11(<4 x double> %a) {
147 ; CHECK-LABEL: test11:
149 ; CHECK-NEXT: vbroadcastf128 {{.*#+}} ymm1 = [5.0E-1,2.5E+0,5.0E-1,2.5E+0]
150 ; CHECK-NEXT: # ymm1 = mem[0,1,0,1]
151 ; CHECK-NEXT: vaddpd %ymm1, %ymm0, %ymm0
152 ; CHECK-NEXT: vfmsub213pd {{.*#+}} ymm0 = (ymm1 * ymm0) - ymm1
153 ; CHECK-NEXT: ret{{[l|q]}}
154 %t0 = fadd <4 x double> %a, <double 5.000000e-01, double 25.00000e-01, double 5.000000e-01, double 25.00000e-01>
155 %t1 = tail call <4 x double> @llvm.fma.v4f64(<4 x double> %t0, <4 x double> <double 5.000000e-01, double 25.00000e-01, double 5.000000e-01, double 25.00000e-01>, <4 x double> <double -5.000000e-01, double -25.00000e-01, double -5.000000e-01, double -25.00000e-01>)
159 define <4 x double> @test12(<4 x double> %a, <4 x double> %b) {
160 ; CHECK-LABEL: test12:
162 ; CHECK-NEXT: vmovapd {{.*#+}} ymm2 = [-7.5E+0,-2.5E+0,-5.5E+0,-9.5E+0]
163 ; CHECK-NEXT: vfnmadd213pd {{.*#+}} ymm0 = -(ymm2 * ymm0) + mem
164 ; CHECK-NEXT: vfmadd132pd {{.*#+}} ymm1 = (ymm1 * mem) + ymm2
165 ; CHECK-NEXT: vaddpd %ymm1, %ymm0, %ymm0
166 ; CHECK-NEXT: ret{{[l|q]}}
167 %t0 = tail call <4 x double> @llvm.fma.v4f64(<4 x double> %a, <4 x double> <double 75.00000e-01, double 25.00000e-01, double 55.00000e-01, double 95.00000e-01>, <4 x double> <double -75.00000e-01, double undef, double -55.00000e-01, double -95.00000e-01>)
168 %t1 = tail call <4 x double> @llvm.fma.v4f64(<4 x double> %b, <4 x double> <double undef, double 25.00000e-01, double 55.00000e-01, double 95.00000e-01>, <4 x double> <double -75.00000e-01, double -25.00000e-01, double -55.00000e-01, double -95.00000e-01>)
169 %t2 = fadd <4 x double> %t0, %t1