blob: 670f3f0b697845e28f9dafcb581df0d91d266aef [file] [log] [blame]
Dan Gohmanb7c24002016-05-21 00:21:56 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt | FileCheck %s
JF Bastienef172fc2015-08-11 02:45:15 +00002
3; Test that basic 64-bit floating-point operations assemble as expected.
4
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00005target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
JF Bastienef172fc2015-08-11 02:45:15 +00006target triple = "wasm32-unknown-unknown"
7
8declare double @llvm.fabs.f64(double)
9declare double @llvm.copysign.f64(double, double)
10declare double @llvm.sqrt.f64(double)
Dan Gohman896e53f2015-08-24 18:23:13 +000011declare double @llvm.ceil.f64(double)
12declare double @llvm.floor.f64(double)
13declare double @llvm.trunc.f64(double)
14declare double @llvm.nearbyint.f64(double)
15declare double @llvm.rint.f64(double)
Dan Gohman9341c1d2015-12-10 04:52:33 +000016declare double @llvm.fma.f64(double, double, double)
JF Bastienef172fc2015-08-11 02:45:15 +000017
Dan Gohmane51c0582015-10-06 00:27:55 +000018; CHECK-LABEL: fadd64:
Dan Gohman53828fd2015-11-23 16:50:18 +000019; CHECK-NEXT: .param f64, f64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000020; CHECK-NEXT: .result f64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000021; CHECK-NEXT: f64.add $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000022; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000023define double @fadd64(double %x, double %y) {
24 %a = fadd double %x, %y
25 ret double %a
26}
27
Dan Gohmane51c0582015-10-06 00:27:55 +000028; CHECK-LABEL: fsub64:
Dan Gohman700515f2015-11-23 21:55:57 +000029; CHECK: f64.sub $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000030; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000031define double @fsub64(double %x, double %y) {
32 %a = fsub double %x, %y
33 ret double %a
34}
35
Dan Gohmane51c0582015-10-06 00:27:55 +000036; CHECK-LABEL: fmul64:
Dan Gohman700515f2015-11-23 21:55:57 +000037; CHECK: f64.mul $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000038; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000039define double @fmul64(double %x, double %y) {
40 %a = fmul double %x, %y
41 ret double %a
42}
43
Dan Gohmane51c0582015-10-06 00:27:55 +000044; CHECK-LABEL: fdiv64:
Dan Gohman700515f2015-11-23 21:55:57 +000045; CHECK: f64.div $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000046; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000047define double @fdiv64(double %x, double %y) {
48 %a = fdiv double %x, %y
49 ret double %a
50}
51
Dan Gohmane51c0582015-10-06 00:27:55 +000052; CHECK-LABEL: fabs64:
Dan Gohman700515f2015-11-23 21:55:57 +000053; CHECK: f64.abs $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000054; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000055define double @fabs64(double %x) {
56 %a = call double @llvm.fabs.f64(double %x)
57 ret double %a
58}
59
Dan Gohmane51c0582015-10-06 00:27:55 +000060; CHECK-LABEL: fneg64:
Dan Gohman700515f2015-11-23 21:55:57 +000061; CHECK: f64.neg $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000062; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000063define double @fneg64(double %x) {
64 %a = fsub double -0., %x
65 ret double %a
66}
67
Dan Gohmane51c0582015-10-06 00:27:55 +000068; CHECK-LABEL: copysign64:
Dan Gohman700515f2015-11-23 21:55:57 +000069; CHECK: f64.copysign $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000070; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000071define double @copysign64(double %x, double %y) {
72 %a = call double @llvm.copysign.f64(double %x, double %y)
73 ret double %a
74}
75
Dan Gohmane51c0582015-10-06 00:27:55 +000076; CHECK-LABEL: sqrt64:
Dan Gohman700515f2015-11-23 21:55:57 +000077; CHECK: f64.sqrt $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000078; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000079define double @sqrt64(double %x) {
80 %a = call double @llvm.sqrt.f64(double %x)
81 ret double %a
82}
Dan Gohman896e53f2015-08-24 18:23:13 +000083
Dan Gohmane51c0582015-10-06 00:27:55 +000084; CHECK-LABEL: ceil64:
Dan Gohman700515f2015-11-23 21:55:57 +000085; CHECK: f64.ceil $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000086; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000087define double @ceil64(double %x) {
88 %a = call double @llvm.ceil.f64(double %x)
89 ret double %a
90}
91
Dan Gohmane51c0582015-10-06 00:27:55 +000092; CHECK-LABEL: floor64:
Dan Gohman700515f2015-11-23 21:55:57 +000093; CHECK: f64.floor $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000094; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000095define double @floor64(double %x) {
96 %a = call double @llvm.floor.f64(double %x)
97 ret double %a
98}
99
Dan Gohmane51c0582015-10-06 00:27:55 +0000100; CHECK-LABEL: trunc64:
Dan Gohman700515f2015-11-23 21:55:57 +0000101; CHECK: f64.trunc $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000102; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000103define double @trunc64(double %x) {
104 %a = call double @llvm.trunc.f64(double %x)
105 ret double %a
106}
107
Dan Gohmane51c0582015-10-06 00:27:55 +0000108; CHECK-LABEL: nearest64:
Dan Gohman700515f2015-11-23 21:55:57 +0000109; CHECK: f64.nearest $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000110; CHECK-NEXT: return $pop0{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000111define double @nearest64(double %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000112 %a = call double @llvm.nearbyint.f64(double %x)
113 ret double %a
114}
115
Dan Gohmane51c0582015-10-06 00:27:55 +0000116; CHECK-LABEL: nearest64_via_rint:
Dan Gohman700515f2015-11-23 21:55:57 +0000117; CHECK: f64.nearest $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000118; CHECK-NEXT: return $pop0{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000119define double @nearest64_via_rint(double %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000120 %a = call double @llvm.rint.f64(double %x)
121 ret double %a
122}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000123
124; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in
125; cases where there's a single fcmp with a select and it can prove that one
126; of the arms is never NaN, so we only test that case. In the future if LLVM
127; learns to form fminnan/fmaxnan in more cases, we can write more general
128; tests.
129
130; CHECK-LABEL: fmin64:
Dan Gohman700515f2015-11-23 21:55:57 +0000131; CHECK: f64.min $push1=, $0, $pop0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000132; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000133define double @fmin64(double %x) {
134 %a = fcmp ult double %x, 0.0
135 %b = select i1 %a, double %x, double 0.0
136 ret double %b
137}
138
139; CHECK-LABEL: fmax64:
Dan Gohman700515f2015-11-23 21:55:57 +0000140; CHECK: f64.max $push1=, $0, $pop0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000141; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000142define double @fmax64(double %x) {
143 %a = fcmp ugt double %x, 0.0
144 %b = select i1 %a, double %x, double 0.0
145 ret double %b
146}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000147
148; CHECK-LABEL: fma64:
Dan Gohman26c67652016-01-11 23:38:05 +0000149; CHECK: {{^}} f64.call $push0=, fma@FUNCTION, $0, $1, $2{{$}}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000150; CHECK-NEXT: return $pop0{{$}}
151define double @fma64(double %a, double %b, double %c) {
152 %d = call double @llvm.fma.f64(double %a, double %b, double %c)
153 ret double %d
154}