blob: 45912912d814192d45fd92767dfea89b16989930 [file] [log] [blame]
Wouter van Oortmerssen8a9cb242018-08-27 15:45:51 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck %s
JF Bastienef172fc2015-08-11 02:45:15 +00002
3; Test that basic 32-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"
Sam Clegga5908002018-05-10 17:49:11 +00006target triple = "wasm32-unknown-unknown"
JF Bastienef172fc2015-08-11 02:45:15 +00007
8declare float @llvm.fabs.f32(float)
9declare float @llvm.copysign.f32(float, float)
10declare float @llvm.sqrt.f32(float)
Dan Gohman896e53f2015-08-24 18:23:13 +000011declare float @llvm.ceil.f32(float)
12declare float @llvm.floor.f32(float)
13declare float @llvm.trunc.f32(float)
14declare float @llvm.nearbyint.f32(float)
15declare float @llvm.rint.f32(float)
Dan Gohman9341c1d2015-12-10 04:52:33 +000016declare float @llvm.fma.f32(float, float, float)
JF Bastienef172fc2015-08-11 02:45:15 +000017
Dan Gohmane51c0582015-10-06 00:27:55 +000018; CHECK-LABEL: fadd32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000019; CHECK-NEXT: .functype fadd32 (f32, f32) -> (f32){{$}}
Thomas Lively6a87dda2019-01-08 06:25:55 +000020; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
21; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000022; CHECK-NEXT: f32.add $push[[LR:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
23; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000024define float @fadd32(float %x, float %y) {
25 %a = fadd float %x, %y
26 ret float %a
27}
28
Dan Gohmane51c0582015-10-06 00:27:55 +000029; CHECK-LABEL: fsub32:
Dan Gohmand934cb82017-02-24 23:18:00 +000030; CHECK: f32.sub $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
31; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000032define float @fsub32(float %x, float %y) {
33 %a = fsub float %x, %y
34 ret float %a
35}
36
Dan Gohmane51c0582015-10-06 00:27:55 +000037; CHECK-LABEL: fmul32:
Dan Gohmand934cb82017-02-24 23:18:00 +000038; CHECK: f32.mul $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
39; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000040define float @fmul32(float %x, float %y) {
41 %a = fmul float %x, %y
42 ret float %a
43}
44
Dan Gohmane51c0582015-10-06 00:27:55 +000045; CHECK-LABEL: fdiv32:
Dan Gohmand934cb82017-02-24 23:18:00 +000046; CHECK: f32.div $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
47; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000048define float @fdiv32(float %x, float %y) {
49 %a = fdiv float %x, %y
50 ret float %a
51}
52
Dan Gohmane51c0582015-10-06 00:27:55 +000053; CHECK-LABEL: fabs32:
Dan Gohmand934cb82017-02-24 23:18:00 +000054; CHECK: f32.abs $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
55; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000056define float @fabs32(float %x) {
57 %a = call float @llvm.fabs.f32(float %x)
58 ret float %a
59}
60
Dan Gohmane51c0582015-10-06 00:27:55 +000061; CHECK-LABEL: fneg32:
Dan Gohmand934cb82017-02-24 23:18:00 +000062; CHECK: f32.neg $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
63; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000064define float @fneg32(float %x) {
65 %a = fsub float -0., %x
66 ret float %a
67}
68
Dan Gohmane51c0582015-10-06 00:27:55 +000069; CHECK-LABEL: copysign32:
Dan Gohmand934cb82017-02-24 23:18:00 +000070; CHECK: f32.copysign $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
71; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000072define float @copysign32(float %x, float %y) {
73 %a = call float @llvm.copysign.f32(float %x, float %y)
74 ret float %a
75}
76
Dan Gohmane51c0582015-10-06 00:27:55 +000077; CHECK-LABEL: sqrt32:
Dan Gohmand934cb82017-02-24 23:18:00 +000078; CHECK: f32.sqrt $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
79; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000080define float @sqrt32(float %x) {
81 %a = call float @llvm.sqrt.f32(float %x)
82 ret float %a
83}
Dan Gohman896e53f2015-08-24 18:23:13 +000084
Dan Gohmane51c0582015-10-06 00:27:55 +000085; CHECK-LABEL: ceil32:
Dan Gohmand934cb82017-02-24 23:18:00 +000086; CHECK: f32.ceil $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
87; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000088define float @ceil32(float %x) {
89 %a = call float @llvm.ceil.f32(float %x)
90 ret float %a
91}
92
Dan Gohmane51c0582015-10-06 00:27:55 +000093; CHECK-LABEL: floor32:
Dan Gohmand934cb82017-02-24 23:18:00 +000094; CHECK: f32.floor $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
95; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000096define float @floor32(float %x) {
97 %a = call float @llvm.floor.f32(float %x)
98 ret float %a
99}
100
Dan Gohmane51c0582015-10-06 00:27:55 +0000101; CHECK-LABEL: trunc32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000102; CHECK: f32.trunc $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
103; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000104define float @trunc32(float %x) {
105 %a = call float @llvm.trunc.f32(float %x)
106 ret float %a
107}
108
Dan Gohmane51c0582015-10-06 00:27:55 +0000109; CHECK-LABEL: nearest32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000110; CHECK: f32.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
111; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000112define float @nearest32(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000113 %a = call float @llvm.nearbyint.f32(float %x)
114 ret float %a
115}
116
Dan Gohmane51c0582015-10-06 00:27:55 +0000117; CHECK-LABEL: nearest32_via_rint:
Dan Gohmand934cb82017-02-24 23:18:00 +0000118; CHECK: f32.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
119; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000120define float @nearest32_via_rint(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000121 %a = call float @llvm.rint.f32(float %x)
122 ret float %a
123}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000124
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000125; CHECK-LABEL: fmin32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000126; CHECK: f32.min $push1=, $pop{{[0-9]+}}, $pop[[LR]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000127; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000128define float @fmin32(float %x) {
129 %a = fcmp ult float %x, 0.0
130 %b = select i1 %a, float %x, float 0.0
131 ret float %b
132}
133
134; CHECK-LABEL: fmax32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000135; CHECK: f32.max $push1=, $pop{{[0-9]+}}, $pop[[LR]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000136; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000137define float @fmax32(float %x) {
138 %a = fcmp ugt float %x, 0.0
139 %b = select i1 %a, float %x, float 0.0
140 ret float %b
141}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000142
Thomas Lively3afc3462018-10-13 07:26:10 +0000143; CHECK-LABEL: fmin32_intrinsic:
144; CHECK: f32.min $push0=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
145; CHECK-NEXT: return $pop0{{$}}
146declare float @llvm.minimum.f32(float, float)
147define float @fmin32_intrinsic(float %x, float %y) {
148 %a = call float @llvm.minimum.f32(float %x, float %y)
149 ret float %a
150}
151
152; CHECK-LABEL: fmax32_intrinsic:
153; CHECK: f32.max $push0=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
154; CHECK-NEXT: return $pop0{{$}}
155declare float @llvm.maximum.f32(float, float)
156define float @fmax32_intrinsic(float %x, float %y) {
157 %a = call float @llvm.maximum.f32(float %x, float %y)
158 ret float %a
159}
160
Dan Gohman9341c1d2015-12-10 04:52:33 +0000161; CHECK-LABEL: fma32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000162; CHECK: {{^}} f32.call $push[[LR:[0-9]+]]=, fmaf@FUNCTION, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
163; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000164define float @fma32(float %a, float %b, float %c) {
165 %d = call float @llvm.fma.f32(float %a, float %b, float %c)
166 ret float %d
167}