1 ; RUN: llc < %s -mtriple=armv7-eabi -mattr=+neon,+vfp4 -fp-contract=fast | FileCheck %s
2 ; RUN: llc < %s -mtriple=arm-arm-eabi -mcpu=cortex-m7 -fp-contract=fast | FileCheck %s
3 ; RUN: llc < %s -mtriple=arm-arm-eabi -mcpu=cortex-m4 -fp-contract=fast | FileCheck %s -check-prefix=DONT-FUSE
4 ; RUN: llc < %s -mtriple=arm-arm-eabi -mcpu=cortex-m33 -fp-contract=fast | FileCheck %s -check-prefix=DONT-FUSE
6 ; Check generated fused MAC and MLS.
8 define double @fusedMACTest1(double %d1, double %d2, double %d3) {
9 ;CHECK-LABEL: fusedMACTest1:
11 %1 = fmul double %d1, %d2
12 %2 = fadd double %1, %d3
16 define float @fusedMACTest2(float %f1, float %f2, float %f3) {
17 ;CHECK-LABEL: fusedMACTest2:
20 ;DONT-FUSE-LABEL: fusedMACTest2:
22 ;DONT-FUSE-NEXT: vadd.f32
24 %1 = fmul float %f1, %f2
25 %2 = fadd float %1, %f3
29 define double @fusedMACTest3(double %d1, double %d2, double %d3) {
30 ;CHECK-LABEL: fusedMACTest3:
32 %1 = fmul double %d2, %d3
33 %2 = fsub double %d1, %1
37 define float @fusedMACTest4(float %f1, float %f2, float %f3) {
38 ;CHECK-LABEL: fusedMACTest4:
40 %1 = fmul float %f2, %f3
41 %2 = fsub float %f1, %1
45 define double @fusedMACTest5(double %d1, double %d2, double %d3) {
46 ;CHECK-LABEL: fusedMACTest5:
48 %1 = fmul double %d1, %d2
49 %2 = fsub double -0.0, %1
50 %3 = fsub double %2, %d3
54 define float @fusedMACTest6(float %f1, float %f2, float %f3) {
55 ;CHECK-LABEL: fusedMACTest6:
57 %1 = fmul float %f1, %f2
58 %2 = fsub float -0.0, %1
59 %3 = fsub float %2, %f3
63 define double @fusedMACTest7(double %d1, double %d2, double %d3) {
64 ;CHECK-LABEL: fusedMACTest7:
66 %1 = fmul double %d1, %d2
67 %2 = fsub double %1, %d3
71 define float @fusedMACTest8(float %f1, float %f2, float %f3) {
72 ;CHECK-LABEL: fusedMACTest8:
74 %1 = fmul float %f1, %f2
75 %2 = fsub float %1, %f3
79 define <2 x float> @fusedMACTest9(<2 x float> %a, <2 x float> %b) {
80 ;CHECK-LABEL: fusedMACTest9:
82 %mul = fmul <2 x float> %a, %b
83 %add = fadd <2 x float> %mul, %a
87 define <2 x float> @fusedMACTest10(<2 x float> %a, <2 x float> %b) {
88 ;CHECK-LABEL: fusedMACTest10:
90 %mul = fmul <2 x float> %a, %b
91 %sub = fsub <2 x float> %a, %mul
95 define <4 x float> @fusedMACTest11(<4 x float> %a, <4 x float> %b) {
96 ;CHECK-LABEL: fusedMACTest11:
98 %mul = fmul <4 x float> %a, %b
99 %add = fadd <4 x float> %mul, %a
103 define <4 x float> @fusedMACTest12(<4 x float> %a, <4 x float> %b) {
104 ;CHECK-LABEL: fusedMACTest12:
106 %mul = fmul <4 x float> %a, %b
107 %sub = fsub <4 x float> %a, %mul
111 define float @test_fma_f32(float %a, float %b, float %c) nounwind readnone ssp {
113 ; CHECK: test_fma_f32
115 %tmp1 = tail call float @llvm.fma.f32(float %a, float %b, float %c) nounwind readnone
119 define double @test_fma_f64(double %a, double %b, double %c) nounwind readnone ssp {
121 ; CHECK: test_fma_f64
123 %tmp1 = tail call double @llvm.fma.f64(double %a, double %b, double %c) nounwind readnone
127 define <2 x float> @test_fma_v2f32(<2 x float> %a, <2 x float> %b, <2 x float> %c) nounwind readnone ssp {
129 ; CHECK: test_fma_v2f32
131 %tmp1 = tail call <2 x float> @llvm.fma.v2f32(<2 x float> %a, <2 x float> %b, <2 x float> %c) nounwind
132 ret <2 x float> %tmp1
135 define double @test_fms_f64(double %a, double %b, double %c) nounwind readnone ssp {
137 ; CHECK: test_fms_f64
139 %tmp1 = fsub double -0.0, %a
140 %tmp2 = tail call double @llvm.fma.f64(double %tmp1, double %b, double %c) nounwind readnone
144 define double @test_fms_f64_2(double %a, double %b, double %c) nounwind readnone ssp {
146 ; CHECK: test_fms_f64_2
148 %tmp1 = fsub double -0.0, %b
149 %tmp2 = tail call double @llvm.fma.f64(double %a, double %tmp1, double %c) nounwind readnone
153 define float @test_fnms_f32(float %a, float %b, float* %c) nounwind readnone ssp {
154 ; CHECK: test_fnms_f32
156 %tmp1 = load float, float* %c, align 4
157 %tmp2 = fsub float -0.0, %tmp1
158 %tmp3 = tail call float @llvm.fma.f32(float %a, float %b, float %tmp2) nounwind readnone
162 define double @test_fnms_f64(double %a, double %b, double %c) nounwind readnone ssp {
164 ; CHECK: test_fnms_f64
166 %tmp1 = fsub double -0.0, %a
167 %tmp2 = tail call double @llvm.fma.f64(double %tmp1, double %b, double %c) nounwind readnone
168 %tmp3 = fsub double -0.0, %tmp2
172 define double @test_fnms_f64_2(double %a, double %b, double %c) nounwind readnone ssp {
174 ; CHECK: test_fnms_f64_2
176 %tmp1 = fsub double -0.0, %b
177 %tmp2 = tail call double @llvm.fma.f64(double %a, double %tmp1, double %c) nounwind readnone
178 %tmp3 = fsub double -0.0, %tmp2
182 define double @test_fnma_f64(double %a, double %b, double %c) nounwind readnone ssp {
184 ; CHECK: test_fnma_f64
186 %tmp1 = tail call double @llvm.fma.f64(double %a, double %b, double %c) nounwind readnone
187 %tmp2 = fsub double -0.0, %tmp1
191 define double @test_fnma_f64_2(double %a, double %b, double %c) nounwind readnone ssp {
193 ; CHECK: test_fnma_f64_2
195 %tmp1 = fsub double -0.0, %a
196 %tmp2 = fsub double -0.0, %c
197 %tmp3 = tail call double @llvm.fma.f64(double %tmp1, double %b, double %tmp2) nounwind readnone
201 define float @test_fma_const_fold(float %a, float %b) nounwind {
202 ; CHECK: test_fma_const_fold
206 %ret = call float @llvm.fma.f32(float %a, float 1.0, float %b)
210 define float @test_fma_canonicalize(float %a, float %b) nounwind {
211 ; CHECK: test_fma_canonicalize
212 ; CHECK: vmov.f32 [[R1:s[0-9]+]], #2.000000e+00
213 ; CHECK: vfma.f32 {{s[0-9]+}}, {{s[0-9]+}}, [[R1]]
214 %ret = call float @llvm.fma.f32(float 2.0, float %a, float %b)
218 ; Check that very wide vector fma's can be split into legal fma's.
219 define void @test_fma_v8f32(<8 x float> %a, <8 x float> %b, <8 x float> %c, <8 x float>* %p) nounwind readnone ssp {
220 ; CHECK: test_fma_v8f32
224 %call = tail call <8 x float> @llvm.fma.v8f32(<8 x float> %a, <8 x float> %b, <8 x float> %c) nounwind readnone
225 store <8 x float> %call, <8 x float>* %p, align 16
230 declare float @llvm.fma.f32(float, float, float) nounwind readnone
231 declare double @llvm.fma.f64(double, double, double) nounwind readnone
232 declare <2 x float> @llvm.fma.v2f32(<2 x float>, <2 x float>, <2 x float>) nounwind readnone
233 declare <8 x float> @llvm.fma.v8f32(<8 x float>, <8 x float>, <8 x float>) nounwind readnone