blob: 45f00aa5a01fd7d16094c63d20134a0e639f61b0 [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 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"
Dan Gohmand934cb82017-02-24 23:18:00 +00006target triple = "wasm32-unknown-unknown-wasm"
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:
Dan Gohman53828fd2015-11-23 16:50:18 +000019; CHECK-NEXT: .param f32, f32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000020; CHECK-NEXT: .result f32{{$}}
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: f32.add $push[[LR:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
24; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000025define float @fadd32(float %x, float %y) {
26 %a = fadd float %x, %y
27 ret float %a
28}
29
Dan Gohmane51c0582015-10-06 00:27:55 +000030; CHECK-LABEL: fsub32:
Dan Gohmand934cb82017-02-24 23:18:00 +000031; CHECK: f32.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 float @fsub32(float %x, float %y) {
34 %a = fsub float %x, %y
35 ret float %a
36}
37
Dan Gohmane51c0582015-10-06 00:27:55 +000038; CHECK-LABEL: fmul32:
Dan Gohmand934cb82017-02-24 23:18:00 +000039; CHECK: f32.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 float @fmul32(float %x, float %y) {
42 %a = fmul float %x, %y
43 ret float %a
44}
45
Dan Gohmane51c0582015-10-06 00:27:55 +000046; CHECK-LABEL: fdiv32:
Dan Gohmand934cb82017-02-24 23:18:00 +000047; CHECK: f32.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 float @fdiv32(float %x, float %y) {
50 %a = fdiv float %x, %y
51 ret float %a
52}
53
Dan Gohmane51c0582015-10-06 00:27:55 +000054; CHECK-LABEL: fabs32:
Dan Gohmand934cb82017-02-24 23:18:00 +000055; CHECK: f32.abs $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
56; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000057define float @fabs32(float %x) {
58 %a = call float @llvm.fabs.f32(float %x)
59 ret float %a
60}
61
Dan Gohmane51c0582015-10-06 00:27:55 +000062; CHECK-LABEL: fneg32:
Dan Gohmand934cb82017-02-24 23:18:00 +000063; CHECK: f32.neg $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
64; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000065define float @fneg32(float %x) {
66 %a = fsub float -0., %x
67 ret float %a
68}
69
Dan Gohmane51c0582015-10-06 00:27:55 +000070; CHECK-LABEL: copysign32:
Dan Gohmand934cb82017-02-24 23:18:00 +000071; CHECK: f32.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 float @copysign32(float %x, float %y) {
74 %a = call float @llvm.copysign.f32(float %x, float %y)
75 ret float %a
76}
77
Dan Gohmane51c0582015-10-06 00:27:55 +000078; CHECK-LABEL: sqrt32:
Dan Gohmand934cb82017-02-24 23:18:00 +000079; CHECK: f32.sqrt $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
80; CHECK-NEXT: return $pop[[LR]]{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000081define float @sqrt32(float %x) {
82 %a = call float @llvm.sqrt.f32(float %x)
83 ret float %a
84}
Dan Gohman896e53f2015-08-24 18:23:13 +000085
Dan Gohmane51c0582015-10-06 00:27:55 +000086; CHECK-LABEL: ceil32:
Dan Gohmand934cb82017-02-24 23:18:00 +000087; CHECK: f32.ceil $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
88; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000089define float @ceil32(float %x) {
90 %a = call float @llvm.ceil.f32(float %x)
91 ret float %a
92}
93
Dan Gohmane51c0582015-10-06 00:27:55 +000094; CHECK-LABEL: floor32:
Dan Gohmand934cb82017-02-24 23:18:00 +000095; CHECK: f32.floor $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
96; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000097define float @floor32(float %x) {
98 %a = call float @llvm.floor.f32(float %x)
99 ret float %a
100}
101
Dan Gohmane51c0582015-10-06 00:27:55 +0000102; CHECK-LABEL: trunc32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000103; CHECK: f32.trunc $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
104; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000105define float @trunc32(float %x) {
106 %a = call float @llvm.trunc.f32(float %x)
107 ret float %a
108}
109
Dan Gohmane51c0582015-10-06 00:27:55 +0000110; CHECK-LABEL: nearest32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000111; CHECK: f32.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
112; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000113define float @nearest32(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000114 %a = call float @llvm.nearbyint.f32(float %x)
115 ret float %a
116}
117
Dan Gohmane51c0582015-10-06 00:27:55 +0000118; CHECK-LABEL: nearest32_via_rint:
Dan Gohmand934cb82017-02-24 23:18:00 +0000119; CHECK: f32.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}}
120; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000121define float @nearest32_via_rint(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000122 %a = call float @llvm.rint.f32(float %x)
123 ret float %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: fmin32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000133; CHECK: f32.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 float @fmin32(float %x) {
136 %a = fcmp ult float %x, 0.0
137 %b = select i1 %a, float %x, float 0.0
138 ret float %b
139}
140
141; CHECK-LABEL: fmax32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000142; CHECK: f32.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 float @fmax32(float %x) {
145 %a = fcmp ugt float %x, 0.0
146 %b = select i1 %a, float %x, float 0.0
147 ret float %b
148}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000149
150; CHECK-LABEL: fma32:
Dan Gohmand934cb82017-02-24 23:18:00 +0000151; CHECK: {{^}} f32.call $push[[LR:[0-9]+]]=, fmaf@FUNCTION, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
152; CHECK-NEXT: return $pop[[LR]]{{$}}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000153define float @fma32(float %a, float %b, float %c) {
154 %d = call float @llvm.fma.f32(float %a, float %b, float %c)
155 ret float %d
156}