blob: 10f88fdbbe962a46a086b17dabc1f8ace59df7e3 [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001; RUN: llc -verify-machineinstrs -o - %s -mtriple=aarch64-none-linux-gnu -fp-contract=fast | FileCheck %s
Tim Northover221b5832014-04-15 14:00:06 +00002; RUN: llc -verify-machineinstrs -o - %s -mtriple=arm64-apple-ios7.0 | FileCheck %s -check-prefix=CHECK-NOFAST
Tim Northovere0e3aef2013-01-31 12:12:40 +00003
4declare float @llvm.fma.f32(float, float, float)
5declare double @llvm.fma.f64(double, double, double)
6
7define float @test_fmadd(float %a, float %b, float %c) {
Stephen Lin764d8d32013-07-12 14:54:12 +00008; CHECK-LABEL: test_fmadd:
9; CHECK-NOFAST-LABEL: test_fmadd:
Tim Northovere0e3aef2013-01-31 12:12:40 +000010 %val = call float @llvm.fma.f32(float %a, float %b, float %c)
11; CHECK: fmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000012; CHECK-NOFAST: fmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000013 ret float %val
14}
15
16define float @test_fmsub(float %a, float %b, float %c) {
Stephen Lin764d8d32013-07-12 14:54:12 +000017; CHECK-LABEL: test_fmsub:
18; CHECK-NOFAST-LABEL: test_fmsub:
Tim Northovere0e3aef2013-01-31 12:12:40 +000019 %nega = fsub float -0.0, %a
20 %val = call float @llvm.fma.f32(float %nega, float %b, float %c)
21; CHECK: fmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000022; CHECK-NOFAST: fmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000023 ret float %val
24}
25
26define float @test_fnmadd(float %a, float %b, float %c) {
Stephen Lin764d8d32013-07-12 14:54:12 +000027; CHECK-LABEL: test_fnmadd:
28; CHECK-NOFAST-LABEL: test_fnmadd:
Ana Pazos3ca23912013-12-24 00:40:10 +000029 %nega = fsub float -0.0, %a
Tim Northovere0e3aef2013-01-31 12:12:40 +000030 %negc = fsub float -0.0, %c
Ana Pazos3ca23912013-12-24 00:40:10 +000031 %val = call float @llvm.fma.f32(float %nega, float %b, float %negc)
Tim Northovere0e3aef2013-01-31 12:12:40 +000032; CHECK: fnmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000033; CHECK-NOFAST: fnmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000034 ret float %val
35}
36
37define float @test_fnmsub(float %a, float %b, float %c) {
Stephen Lin764d8d32013-07-12 14:54:12 +000038; CHECK-LABEL: test_fnmsub:
39; CHECK-NOFAST-LABEL: test_fnmsub:
Tim Northovere0e3aef2013-01-31 12:12:40 +000040 %negc = fsub float -0.0, %c
Ana Pazos3ca23912013-12-24 00:40:10 +000041 %val = call float @llvm.fma.f32(float %a, float %b, float %negc)
Tim Northovere0e3aef2013-01-31 12:12:40 +000042; CHECK: fnmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000043; CHECK-NOFAST: fnmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000044 ret float %val
45}
46
47define double @testd_fmadd(double %a, double %b, double %c) {
Stephen Linf799e3f2013-07-13 20:38:47 +000048; CHECK-LABEL: testd_fmadd:
Stephen Lind24ab202013-07-14 06:24:09 +000049; CHECK-NOFAST-LABEL: testd_fmadd:
Tim Northovere0e3aef2013-01-31 12:12:40 +000050 %val = call double @llvm.fma.f64(double %a, double %b, double %c)
51; CHECK: fmadd {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000052; CHECK-NOFAST: fmadd {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000053 ret double %val
54}
55
56define double @testd_fmsub(double %a, double %b, double %c) {
Stephen Linf799e3f2013-07-13 20:38:47 +000057; CHECK-LABEL: testd_fmsub:
Stephen Lind24ab202013-07-14 06:24:09 +000058; CHECK-NOFAST-LABEL: testd_fmsub:
Tim Northovere0e3aef2013-01-31 12:12:40 +000059 %nega = fsub double -0.0, %a
60 %val = call double @llvm.fma.f64(double %nega, double %b, double %c)
61; CHECK: fmsub {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000062; CHECK-NOFAST: fmsub {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000063 ret double %val
64}
65
66define double @testd_fnmadd(double %a, double %b, double %c) {
Stephen Linf799e3f2013-07-13 20:38:47 +000067; CHECK-LABEL: testd_fnmadd:
Stephen Lind24ab202013-07-14 06:24:09 +000068; CHECK-NOFAST-LABEL: testd_fnmadd:
Ana Pazos3ca23912013-12-24 00:40:10 +000069 %nega = fsub double -0.0, %a
Tim Northovere0e3aef2013-01-31 12:12:40 +000070 %negc = fsub double -0.0, %c
Ana Pazos3ca23912013-12-24 00:40:10 +000071 %val = call double @llvm.fma.f64(double %nega, double %b, double %negc)
Tim Northovere0e3aef2013-01-31 12:12:40 +000072; CHECK: fnmadd {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000073; CHECK-NOFAST: fnmadd {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000074 ret double %val
75}
76
77define double @testd_fnmsub(double %a, double %b, double %c) {
Stephen Linf799e3f2013-07-13 20:38:47 +000078; CHECK-LABEL: testd_fnmsub:
Stephen Lind24ab202013-07-14 06:24:09 +000079; CHECK-NOFAST-LABEL: testd_fnmsub:
Tim Northovere0e3aef2013-01-31 12:12:40 +000080 %negc = fsub double -0.0, %c
Ana Pazos3ca23912013-12-24 00:40:10 +000081 %val = call double @llvm.fma.f64(double %a, double %b, double %negc)
Tim Northovere0e3aef2013-01-31 12:12:40 +000082; CHECK: fnmsub {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000083; CHECK-NOFAST: fnmsub {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000084 ret double %val
85}
86
87define float @test_fmadd_unfused(float %a, float %b, float %c) {
Stephen Lin764d8d32013-07-12 14:54:12 +000088; CHECK-LABEL: test_fmadd_unfused:
89; CHECK-NOFAST-LABEL: test_fmadd_unfused:
Tim Northovere0e3aef2013-01-31 12:12:40 +000090 %prod = fmul float %b, %c
91 %sum = fadd float %a, %prod
92; CHECK: fmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +000093; CHECK-NOFAST-NOT: fmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
94; CHECK-NOFAST: fmul {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
95; CHECK-NOFAST: fadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +000096 ret float %sum
97}
98
99define float @test_fmsub_unfused(float %a, float %b, float %c) {
Stephen Lin764d8d32013-07-12 14:54:12 +0000100; CHECK-LABEL: test_fmsub_unfused:
101; CHECK-NOFAST-LABEL: test_fmsub_unfused:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000102 %prod = fmul float %b, %c
103 %diff = fsub float %a, %prod
104; CHECK: fmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +0000105; CHECK-NOFAST-NOT: fmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
106; CHECK-NOFAST: fmul {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
107; CHECK-NOFAST: fsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Tim Northovere0e3aef2013-01-31 12:12:40 +0000108 ret float %diff
109}
110
111define float @test_fnmadd_unfused(float %a, float %b, float %c) {
Stephen Lin764d8d32013-07-12 14:54:12 +0000112; CHECK-LABEL: test_fnmadd_unfused:
113; CHECK-NOFAST-LABEL: test_fnmadd_unfused:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000114 %nega = fsub float -0.0, %a
115 %prod = fmul float %b, %c
Ana Pazos3ca23912013-12-24 00:40:10 +0000116 %diff = fsub float %nega, %prod
Tim Northovere0e3aef2013-01-31 12:12:40 +0000117; CHECK: fnmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +0000118; CHECK-NOFAST-NOT: fnmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
119; CHECK-NOFAST: fmul {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
120; CHECK-NOFAST: fsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Ana Pazos3ca23912013-12-24 00:40:10 +0000121; CHECK-NOFAST: ret
122 ret float %diff
Tim Northovere0e3aef2013-01-31 12:12:40 +0000123}
124
125define float @test_fnmsub_unfused(float %a, float %b, float %c) {
Stephen Lin764d8d32013-07-12 14:54:12 +0000126; CHECK-LABEL: test_fnmsub_unfused:
127; CHECK-NOFAST-LABEL: test_fnmsub_unfused:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000128 %nega = fsub float -0.0, %a
129 %prod = fmul float %b, %c
Ana Pazos3ca23912013-12-24 00:40:10 +0000130 %sum = fadd float %nega, %prod
Tim Northovere0e3aef2013-01-31 12:12:40 +0000131; CHECK: fnmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Stephen Lin73de7bf2013-07-09 18:16:56 +0000132; CHECK-NOFAST-NOT: fnmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
Ana Pazos3ca23912013-12-24 00:40:10 +0000133; CHECK-NOFAST: fmul {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
134; CHECK-NOFAST: fsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
135 ret float %sum
Tim Northovere0e3aef2013-01-31 12:12:40 +0000136}
Ana Pazos3ca23912013-12-24 00:40:10 +0000137
Ana Pazosbc2996b2013-12-24 00:47:29 +0000138; Another set of tests that check for multiply single use
139
140define float @test_fmadd_unfused_su(float %a, float %b, float %c) {
141; CHECK-LABEL: test_fmadd_unfused_su:
142 %prod = fmul float %b, %c
143 %sum = fadd float %a, %prod
144 %res = fadd float %sum, %prod
145; CHECK-NOT: fmadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
146; CHECK: fmul {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
147; CHECK: fadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
148; CHECK: fadd {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
149 ret float %res
150}
151
152define float @test_fmsub_unfused_su(float %a, float %b, float %c) {
153; CHECK-LABEL: test_fmsub_unfused_su:
154 %prod = fmul float %b, %c
155 %diff = fsub float %a, %prod
156 %res = fsub float %diff, %prod
157; CHECK-NOT: fmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
158; CHECK: fmul {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
159; CHECK: fsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
160; CHECK: fsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
161 ret float %res
162}
163