blob: 44ab1e6bd59f3ff6cf91c5a075d1874718f7383b [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:
18; CHECK-NEXT: .param f64{{$}}
19; CHECK-NEXT: .param f64{{$}}
20; CHECK-NEXT: .result f64{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000021; CHECK-NEXT: f64.add $push0, $0, $1{{$}}
22; 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 Gohman4ba48162015-11-18 16:12:01 +000029; CHECK: f64.sub $push0, $0, $1{{$}}
30; 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 Gohman4ba48162015-11-18 16:12:01 +000037; CHECK: f64.mul $push0, $0, $1{{$}}
38; 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 Gohman4ba48162015-11-18 16:12:01 +000045; CHECK: f64.div $push0, $0, $1{{$}}
46; 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 Gohman4ba48162015-11-18 16:12:01 +000053; CHECK: f64.abs $push0, $0{{$}}
54; 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 Gohman4ba48162015-11-18 16:12:01 +000061; CHECK: f64.neg $push0, $0{{$}}
62; 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 Gohman4ba48162015-11-18 16:12:01 +000069; CHECK: f64.copysign $push0, $0, $1{{$}}
70; 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 Gohman4ba48162015-11-18 16:12:01 +000077; CHECK: f64.sqrt $push0, $0{{$}}
78; 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 Gohman4ba48162015-11-18 16:12:01 +000085; CHECK: f64.ceil $push0, $0{{$}}
86; 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 Gohman4ba48162015-11-18 16:12:01 +000093; CHECK: f64.floor $push0, $0{{$}}
94; 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 Gohman4ba48162015-11-18 16:12:01 +0000101; CHECK: f64.trunc $push0, $0{{$}}
102; 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 Gohman4ba48162015-11-18 16:12:01 +0000109; CHECK: f64.nearest $push0, $0{{$}}
110; 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 Gohman4ba48162015-11-18 16:12:01 +0000117; CHECK: f64.nearest $push0, $0{{$}}
118; 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 Gohman4ba48162015-11-18 16:12:01 +0000131; CHECK: f64.min $push1, $0, $pop0{{$}}
132; 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 Gohman4ba48162015-11-18 16:12:01 +0000140; CHECK: f64.max $push1, $0, $pop0{{$}}
141; 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}