blob: d5f6f3e7fe383d0da9946ea1af0fb3d5a33ca5da [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 Gohman8d456e42015-11-06 21:26:50 +000022; CHECK-NEXT: get_local push, 1{{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000023; CHECK-NEXT: set_local 2, pop{{$}}
Dan Gohman8d456e42015-11-06 21:26:50 +000024; CHECK-NEXT: get_local push, 0{{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000025; CHECK-NEXT: set_local 3, pop{{$}}
Dan Gohman3cb66c82015-11-06 21:32:42 +000026; CHECK-NEXT: f64.add push, (get_local 3), (get_local 2){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000027; CHECK-NEXT: set_local 4, pop{{$}}
28; CHECK-NEXT: return (get_local 4){{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000029define double @fadd64(double %x, double %y) {
30 %a = fadd double %x, %y
31 ret double %a
32}
33
Dan Gohmane51c0582015-10-06 00:27:55 +000034; CHECK-LABEL: fsub64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000035; CHECK: f64.sub push, (get_local 3), (get_local 2){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000036; CHECK-NEXT: set_local 4, pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000037define double @fsub64(double %x, double %y) {
38 %a = fsub double %x, %y
39 ret double %a
40}
41
Dan Gohmane51c0582015-10-06 00:27:55 +000042; CHECK-LABEL: fmul64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000043; CHECK: f64.mul push, (get_local 3), (get_local 2){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000044; CHECK-NEXT: set_local 4, pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000045define double @fmul64(double %x, double %y) {
46 %a = fmul double %x, %y
47 ret double %a
48}
49
Dan Gohmane51c0582015-10-06 00:27:55 +000050; CHECK-LABEL: fdiv64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000051; CHECK: f64.div push, (get_local 3), (get_local 2){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000052; CHECK-NEXT: set_local 4, pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000053define double @fdiv64(double %x, double %y) {
54 %a = fdiv double %x, %y
55 ret double %a
56}
57
Dan Gohmane51c0582015-10-06 00:27:55 +000058; CHECK-LABEL: fabs64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000059; CHECK: f64.abs push, (get_local 1){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000060; CHECK-NEXT: set_local 2, pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000061define double @fabs64(double %x) {
62 %a = call double @llvm.fabs.f64(double %x)
63 ret double %a
64}
65
Dan Gohmane51c0582015-10-06 00:27:55 +000066; CHECK-LABEL: fneg64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000067; CHECK: f64.neg push, (get_local 1){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000068; CHECK-NEXT: set_local 2, pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000069define double @fneg64(double %x) {
70 %a = fsub double -0., %x
71 ret double %a
72}
73
Dan Gohmane51c0582015-10-06 00:27:55 +000074; CHECK-LABEL: copysign64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000075; CHECK: f64.copysign push, (get_local 3), (get_local 2){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000076; CHECK-NEXT: set_local 4, pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000077define double @copysign64(double %x, double %y) {
78 %a = call double @llvm.copysign.f64(double %x, double %y)
79 ret double %a
80}
81
Dan Gohmane51c0582015-10-06 00:27:55 +000082; CHECK-LABEL: sqrt64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000083; CHECK: f64.sqrt push, (get_local 1){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000084; CHECK-NEXT: set_local 2, pop{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000085define double @sqrt64(double %x) {
86 %a = call double @llvm.sqrt.f64(double %x)
87 ret double %a
88}
Dan Gohman896e53f2015-08-24 18:23:13 +000089
Dan Gohmane51c0582015-10-06 00:27:55 +000090; CHECK-LABEL: ceil64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000091; CHECK: f64.ceil push, (get_local 1){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000092; CHECK-NEXT: set_local 2, pop{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000093define double @ceil64(double %x) {
94 %a = call double @llvm.ceil.f64(double %x)
95 ret double %a
96}
97
Dan Gohmane51c0582015-10-06 00:27:55 +000098; CHECK-LABEL: floor64:
Dan Gohman3cb66c82015-11-06 21:32:42 +000099; CHECK: f64.floor push, (get_local 1){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +0000100; CHECK-NEXT: set_local 2, pop{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000101define double @floor64(double %x) {
102 %a = call double @llvm.floor.f64(double %x)
103 ret double %a
104}
105
Dan Gohmane51c0582015-10-06 00:27:55 +0000106; CHECK-LABEL: trunc64:
Dan Gohman3cb66c82015-11-06 21:32:42 +0000107; CHECK: f64.trunc push, (get_local 1){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +0000108; CHECK-NEXT: set_local 2, pop{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000109define double @trunc64(double %x) {
110 %a = call double @llvm.trunc.f64(double %x)
111 ret double %a
112}
113
Dan Gohmane51c0582015-10-06 00:27:55 +0000114; CHECK-LABEL: nearest64:
Dan Gohman3cb66c82015-11-06 21:32:42 +0000115; CHECK: f64.nearest push, (get_local 1){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +0000116; CHECK-NEXT: set_local 2, pop{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000117define double @nearest64(double %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000118 %a = call double @llvm.nearbyint.f64(double %x)
119 ret double %a
120}
121
Dan Gohmane51c0582015-10-06 00:27:55 +0000122; CHECK-LABEL: nearest64_via_rint:
Dan Gohman3cb66c82015-11-06 21:32:42 +0000123; CHECK: f64.nearest push, (get_local 1){{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +0000124; CHECK-NEXT: set_local 2, pop{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000125define double @nearest64_via_rint(double %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000126 %a = call double @llvm.rint.f64(double %x)
127 ret double %a
128}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000129
130; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in
131; cases where there's a single fcmp with a select and it can prove that one
132; of the arms is never NaN, so we only test that case. In the future if LLVM
133; learns to form fminnan/fmaxnan in more cases, we can write more general
134; tests.
135
136; CHECK-LABEL: fmin64:
137; CHECK: f64.min push, (get_local 1), (get_local 2){{$}}
138; CHECK-NEXT: set_local 3, pop{{$}}
139define double @fmin64(double %x) {
140 %a = fcmp ult double %x, 0.0
141 %b = select i1 %a, double %x, double 0.0
142 ret double %b
143}
144
145; CHECK-LABEL: fmax64:
146; CHECK: f64.max push, (get_local 1), (get_local 2){{$}}
147; CHECK-NEXT: set_local 3, pop{{$}}
148define double @fmax64(double %x) {
149 %a = fcmp ugt double %x, 0.0
150 %b = select i1 %a, double %x, double 0.0
151 ret double %b
152}