blob: 3cd68794e384014bca31f878d4502b82c86ac637 [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{{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000021; CHECK-NEXT: .local f64, f64, f64{{$}}
Dan Gohmancf4748f2015-11-12 17:04:33 +000022; CHECK-NEXT: f64.add $push, (get_local 0), (get_local 1){{$}}
23; CHECK-NEXT: set_local 2, $pop{{$}}
24; CHECK-NEXT: return (get_local 2){{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000025define double @fadd64(double %x, double %y) {
26 %a = fadd double %x, %y
27 ret double %a
28}
29
Dan Gohmane51c0582015-10-06 00:27:55 +000030; CHECK-LABEL: fsub64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000031; CHECK: f64.sub $push, (get_local 0), (get_local 1){{$}}
32; CHECK-NEXT: set_local 2, $pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000033define double @fsub64(double %x, double %y) {
34 %a = fsub double %x, %y
35 ret double %a
36}
37
Dan Gohmane51c0582015-10-06 00:27:55 +000038; CHECK-LABEL: fmul64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000039; CHECK: f64.mul $push, (get_local 0), (get_local 1){{$}}
40; CHECK-NEXT: set_local 2, $pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000041define double @fmul64(double %x, double %y) {
42 %a = fmul double %x, %y
43 ret double %a
44}
45
Dan Gohmane51c0582015-10-06 00:27:55 +000046; CHECK-LABEL: fdiv64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000047; CHECK: f64.div $push, (get_local 0), (get_local 1){{$}}
48; CHECK-NEXT: set_local 2, $pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000049define double @fdiv64(double %x, double %y) {
50 %a = fdiv double %x, %y
51 ret double %a
52}
53
Dan Gohmane51c0582015-10-06 00:27:55 +000054; CHECK-LABEL: fabs64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000055; CHECK: f64.abs $push, (get_local 0){{$}}
56; CHECK-NEXT: set_local 1, $pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000057define double @fabs64(double %x) {
58 %a = call double @llvm.fabs.f64(double %x)
59 ret double %a
60}
61
Dan Gohmane51c0582015-10-06 00:27:55 +000062; CHECK-LABEL: fneg64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000063; CHECK: f64.neg $push, (get_local 0){{$}}
64; CHECK-NEXT: set_local 1, $pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000065define double @fneg64(double %x) {
66 %a = fsub double -0., %x
67 ret double %a
68}
69
Dan Gohmane51c0582015-10-06 00:27:55 +000070; CHECK-LABEL: copysign64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000071; CHECK: f64.copysign $push, (get_local 0), (get_local 1){{$}}
72; CHECK-NEXT: set_local 2, $pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000073define double @copysign64(double %x, double %y) {
74 %a = call double @llvm.copysign.f64(double %x, double %y)
75 ret double %a
76}
77
Dan Gohmane51c0582015-10-06 00:27:55 +000078; CHECK-LABEL: sqrt64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000079; CHECK: f64.sqrt $push, (get_local 0){{$}}
80; CHECK-NEXT: set_local 1, $pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000081define double @sqrt64(double %x) {
82 %a = call double @llvm.sqrt.f64(double %x)
83 ret double %a
84}
Dan Gohman896e53f2015-08-24 18:23:13 +000085
Dan Gohmane51c0582015-10-06 00:27:55 +000086; CHECK-LABEL: ceil64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000087; CHECK: f64.ceil $push, (get_local 0){{$}}
88; CHECK-NEXT: set_local 1, $pop{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000089define double @ceil64(double %x) {
90 %a = call double @llvm.ceil.f64(double %x)
91 ret double %a
92}
93
Dan Gohmane51c0582015-10-06 00:27:55 +000094; CHECK-LABEL: floor64:
Dan Gohmancf4748f2015-11-12 17:04:33 +000095; CHECK: f64.floor $push, (get_local 0){{$}}
96; CHECK-NEXT: set_local 1, $pop{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000097define double @floor64(double %x) {
98 %a = call double @llvm.floor.f64(double %x)
99 ret double %a
100}
101
Dan Gohmane51c0582015-10-06 00:27:55 +0000102; CHECK-LABEL: trunc64:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000103; CHECK: f64.trunc $push, (get_local 0){{$}}
104; CHECK-NEXT: set_local 1, $pop{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000105define double @trunc64(double %x) {
106 %a = call double @llvm.trunc.f64(double %x)
107 ret double %a
108}
109
Dan Gohmane51c0582015-10-06 00:27:55 +0000110; CHECK-LABEL: nearest64:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000111; CHECK: f64.nearest $push, (get_local 0){{$}}
112; CHECK-NEXT: set_local 1, $pop{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000113define double @nearest64(double %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000114 %a = call double @llvm.nearbyint.f64(double %x)
115 ret double %a
116}
117
Dan Gohmane51c0582015-10-06 00:27:55 +0000118; CHECK-LABEL: nearest64_via_rint:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000119; CHECK: f64.nearest $push, (get_local 0){{$}}
120; CHECK-NEXT: set_local 1, $pop{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000121define double @nearest64_via_rint(double %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000122 %a = call double @llvm.rint.f64(double %x)
123 ret double %a
124}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000125
126; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in
127; cases where there's a single fcmp with a select and it can prove that one
128; of the arms is never NaN, so we only test that case. In the future if LLVM
129; learns to form fminnan/fmaxnan in more cases, we can write more general
130; tests.
131
132; CHECK-LABEL: fmin64:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000133; CHECK: f64.min $push, (get_local 0), (get_local 1){{$}}
134; CHECK-NEXT: set_local 2, $pop{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000135define double @fmin64(double %x) {
136 %a = fcmp ult double %x, 0.0
137 %b = select i1 %a, double %x, double 0.0
138 ret double %b
139}
140
141; CHECK-LABEL: fmax64:
Dan Gohmancf4748f2015-11-12 17:04:33 +0000142; CHECK: f64.max $push, (get_local 0), (get_local 1){{$}}
143; CHECK-NEXT: set_local 2, $pop{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000144define double @fmax64(double %x) {
145 %a = fcmp ugt double %x, 0.0
146 %b = select i1 %a, double %x, double 0.0
147 ret double %b
148}