blob: 1407f713b48070eb402b7a3b400c21608cf38fd6 [file] [log] [blame]
JF Bastienef172fc2015-08-11 02:45:15 +00001; RUN: llc < %s -asm-verbose=false | FileCheck %s
2
3; Test that basic 64-bit floating-point operations assemble as expected.
4
Dan Gohmandde8dce2015-08-19 20:30:20 +00005target datalayout = "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)
JF Bastienef172fc2015-08-11 02:45:15 +000016
Dan Gohmane51c0582015-10-06 00:27:55 +000017; CHECK-LABEL: fadd64:
Dan Gohman53828fd2015-11-23 16:50:18 +000018; CHECK-NEXT: .param f64, f64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000019; CHECK-NEXT: .result f64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000020; CHECK-NEXT: f64.add $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000021; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000022define double @fadd64(double %x, double %y) {
23 %a = fadd double %x, %y
24 ret double %a
25}
26
Dan Gohmane51c0582015-10-06 00:27:55 +000027; CHECK-LABEL: fsub64:
Dan Gohman700515f2015-11-23 21:55:57 +000028; CHECK: f64.sub $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000029; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000030define double @fsub64(double %x, double %y) {
31 %a = fsub double %x, %y
32 ret double %a
33}
34
Dan Gohmane51c0582015-10-06 00:27:55 +000035; CHECK-LABEL: fmul64:
Dan Gohman700515f2015-11-23 21:55:57 +000036; CHECK: f64.mul $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000037; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000038define double @fmul64(double %x, double %y) {
39 %a = fmul double %x, %y
40 ret double %a
41}
42
Dan Gohmane51c0582015-10-06 00:27:55 +000043; CHECK-LABEL: fdiv64:
Dan Gohman700515f2015-11-23 21:55:57 +000044; CHECK: f64.div $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000045; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000046define double @fdiv64(double %x, double %y) {
47 %a = fdiv double %x, %y
48 ret double %a
49}
50
Dan Gohmane51c0582015-10-06 00:27:55 +000051; CHECK-LABEL: fabs64:
Dan Gohman700515f2015-11-23 21:55:57 +000052; CHECK: f64.abs $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000053; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000054define double @fabs64(double %x) {
55 %a = call double @llvm.fabs.f64(double %x)
56 ret double %a
57}
58
Dan Gohmane51c0582015-10-06 00:27:55 +000059; CHECK-LABEL: fneg64:
Dan Gohman700515f2015-11-23 21:55:57 +000060; CHECK: f64.neg $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000061; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000062define double @fneg64(double %x) {
63 %a = fsub double -0., %x
64 ret double %a
65}
66
Dan Gohmane51c0582015-10-06 00:27:55 +000067; CHECK-LABEL: copysign64:
Dan Gohman700515f2015-11-23 21:55:57 +000068; CHECK: f64.copysign $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000069; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000070define double @copysign64(double %x, double %y) {
71 %a = call double @llvm.copysign.f64(double %x, double %y)
72 ret double %a
73}
74
Dan Gohmane51c0582015-10-06 00:27:55 +000075; CHECK-LABEL: sqrt64:
Dan Gohman700515f2015-11-23 21:55:57 +000076; CHECK: f64.sqrt $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000077; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000078define double @sqrt64(double %x) {
79 %a = call double @llvm.sqrt.f64(double %x)
80 ret double %a
81}
Dan Gohman896e53f2015-08-24 18:23:13 +000082
Dan Gohmane51c0582015-10-06 00:27:55 +000083; CHECK-LABEL: ceil64:
Dan Gohman700515f2015-11-23 21:55:57 +000084; CHECK: f64.ceil $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000085; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000086define double @ceil64(double %x) {
87 %a = call double @llvm.ceil.f64(double %x)
88 ret double %a
89}
90
Dan Gohmane51c0582015-10-06 00:27:55 +000091; CHECK-LABEL: floor64:
Dan Gohman700515f2015-11-23 21:55:57 +000092; CHECK: f64.floor $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000093; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000094define double @floor64(double %x) {
95 %a = call double @llvm.floor.f64(double %x)
96 ret double %a
97}
98
Dan Gohmane51c0582015-10-06 00:27:55 +000099; CHECK-LABEL: trunc64:
Dan Gohman700515f2015-11-23 21:55:57 +0000100; CHECK: f64.trunc $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000101; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000102define double @trunc64(double %x) {
103 %a = call double @llvm.trunc.f64(double %x)
104 ret double %a
105}
106
Dan Gohmane51c0582015-10-06 00:27:55 +0000107; CHECK-LABEL: nearest64:
Dan Gohman700515f2015-11-23 21:55:57 +0000108; CHECK: f64.nearest $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000109; CHECK-NEXT: return $pop0{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000110define double @nearest64(double %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000111 %a = call double @llvm.nearbyint.f64(double %x)
112 ret double %a
113}
114
Dan Gohmane51c0582015-10-06 00:27:55 +0000115; CHECK-LABEL: nearest64_via_rint:
Dan Gohman700515f2015-11-23 21:55:57 +0000116; CHECK: f64.nearest $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000117; CHECK-NEXT: return $pop0{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000118define double @nearest64_via_rint(double %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000119 %a = call double @llvm.rint.f64(double %x)
120 ret double %a
121}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000122
123; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in
124; cases where there's a single fcmp with a select and it can prove that one
125; of the arms is never NaN, so we only test that case. In the future if LLVM
126; learns to form fminnan/fmaxnan in more cases, we can write more general
127; tests.
128
129; CHECK-LABEL: fmin64:
Dan Gohman700515f2015-11-23 21:55:57 +0000130; CHECK: f64.min $push1=, $0, $pop0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000131; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000132define double @fmin64(double %x) {
133 %a = fcmp ult double %x, 0.0
134 %b = select i1 %a, double %x, double 0.0
135 ret double %b
136}
137
138; CHECK-LABEL: fmax64:
Dan Gohman700515f2015-11-23 21:55:57 +0000139; CHECK: f64.max $push1=, $0, $pop0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000140; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000141define double @fmax64(double %x) {
142 %a = fcmp ugt double %x, 0.0
143 %b = select i1 %a, double %x, double 0.0
144 ret double %b
145}