blob: fb52c3f92ad64933a5209a8cf781875959c5be13 [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"
Dan Gohmand934cb82017-02-24 23:18:00 +00006target triple = "wasm32-unknown-unknown-wasm"
JF Bastienef172fc2015-08-11 02:45:15 +00007
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 Gohmand934cb82017-02-24 23:18:00 +000021; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
22; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
23; CHECK-NEXT: f64.add $push[[LR:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
24; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000031; CHECK: f64.sub $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
32; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000039; CHECK: f64.mul $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
40; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000047; CHECK: f64.div $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
48; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000055; CHECK: f64.abs $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
56; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000063; CHECK: f64.neg $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
64; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000071; CHECK: f64.copysign $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
72; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000079; CHECK: f64.sqrt $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
80; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000087; CHECK: f64.ceil $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
88; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +000095; CHECK: f64.floor $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
96; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +0000103; CHECK: f64.trunc $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
104; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +0000111; CHECK: f64.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
112; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +0000119; CHECK: f64.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
120; CHECK-NEXT: return $pop[[LR]]{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +0000133; CHECK: f64.min $push1=, $pop{{[0-9]+}}, $pop[[LR]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000134; CHECK-NEXT: return $pop1{{$}}
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 Gohmand934cb82017-02-24 23:18:00 +0000142; CHECK: f64.max $push1=, $pop{{[0-9]+}}, $pop[[LR]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000143; CHECK-NEXT: return $pop1{{$}}
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}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000149
150; CHECK-LABEL: fma64:
Dan Gohmand934cb82017-02-24 23:18:00 +0000151; CHECK: {{^}} f64.call $push[[LR:[0-9]+]]=, fma@FUNCTION, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
152; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000153define double @fma64(double %a, double %b, double %c) {
154 %d = call double @llvm.fma.f64(double %a, double %b, double %c)
155 ret double %d
156}