blob: 3ae35880d0e369af092dd27793077566f535cc7c [file] [log] [blame]
JF Bastienef172fc2015-08-11 02:45:15 +00001; RUN: llc < %s -asm-verbose=false | FileCheck %s
2
3; Test that basic 32-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 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)
JF Bastienef172fc2015-08-11 02:45:15 +000016
Dan Gohmane51c0582015-10-06 00:27:55 +000017; CHECK-LABEL: fadd32:
18; CHECK-NEXT: .param f32{{$}}
19; CHECK-NEXT: .param f32{{$}}
20; CHECK-NEXT: .result f32{{$}}
JF Bastien1d20a5e2015-10-16 00:53:49 +000021; CHECK-NEXT: .local f32, f32, f32{{$}}
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: f32.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 float @fadd32(float %x, float %y) {
30 %a = fadd float %x, %y
31 ret float %a
32}
33
Dan Gohmane51c0582015-10-06 00:27:55 +000034; CHECK-LABEL: fsub32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000035; CHECK: f32.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 float @fsub32(float %x, float %y) {
38 %a = fsub float %x, %y
39 ret float %a
40}
41
Dan Gohmane51c0582015-10-06 00:27:55 +000042; CHECK-LABEL: fmul32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000043; CHECK: f32.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 float @fmul32(float %x, float %y) {
46 %a = fmul float %x, %y
47 ret float %a
48}
49
Dan Gohmane51c0582015-10-06 00:27:55 +000050; CHECK-LABEL: fdiv32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000051; CHECK: f32.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 float @fdiv32(float %x, float %y) {
54 %a = fdiv float %x, %y
55 ret float %a
56}
57
Dan Gohmane51c0582015-10-06 00:27:55 +000058; CHECK-LABEL: fabs32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000059; CHECK: f32.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 float @fabs32(float %x) {
62 %a = call float @llvm.fabs.f32(float %x)
63 ret float %a
64}
65
Dan Gohmane51c0582015-10-06 00:27:55 +000066; CHECK-LABEL: fneg32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000067; CHECK: f32.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 float @fneg32(float %x) {
70 %a = fsub float -0., %x
71 ret float %a
72}
73
Dan Gohmane51c0582015-10-06 00:27:55 +000074; CHECK-LABEL: copysign32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000075; CHECK: f32.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 float @copysign32(float %x, float %y) {
78 %a = call float @llvm.copysign.f32(float %x, float %y)
79 ret float %a
80}
81
Dan Gohmane51c0582015-10-06 00:27:55 +000082; CHECK-LABEL: sqrt32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000083; CHECK: f32.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 float @sqrt32(float %x) {
86 %a = call float @llvm.sqrt.f32(float %x)
87 ret float %a
88}
Dan Gohman896e53f2015-08-24 18:23:13 +000089
Dan Gohmane51c0582015-10-06 00:27:55 +000090; CHECK-LABEL: ceil32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000091; CHECK: f32.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 float @ceil32(float %x) {
94 %a = call float @llvm.ceil.f32(float %x)
95 ret float %a
96}
97
Dan Gohmane51c0582015-10-06 00:27:55 +000098; CHECK-LABEL: floor32:
Dan Gohman3cb66c82015-11-06 21:32:42 +000099; CHECK: f32.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 float @floor32(float %x) {
102 %a = call float @llvm.floor.f32(float %x)
103 ret float %a
104}
105
Dan Gohmane51c0582015-10-06 00:27:55 +0000106; CHECK-LABEL: trunc32:
Dan Gohman3cb66c82015-11-06 21:32:42 +0000107; CHECK: f32.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 float @trunc32(float %x) {
110 %a = call float @llvm.trunc.f32(float %x)
111 ret float %a
112}
113
Dan Gohmane51c0582015-10-06 00:27:55 +0000114; CHECK-LABEL: nearest32:
Dan Gohman3cb66c82015-11-06 21:32:42 +0000115; CHECK: f32.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 float @nearest32(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000118 %a = call float @llvm.nearbyint.f32(float %x)
119 ret float %a
120}
121
Dan Gohmane51c0582015-10-06 00:27:55 +0000122; CHECK-LABEL: nearest32_via_rint:
Dan Gohman3cb66c82015-11-06 21:32:42 +0000123; CHECK: f32.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 float @nearest32_via_rint(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000126 %a = call float @llvm.rint.f32(float %x)
127 ret float %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: fmin32:
137; CHECK: f32.min push, (get_local 1), (get_local 2){{$}}
138; CHECK-NEXT: set_local 3, pop{{$}}
139define float @fmin32(float %x) {
140 %a = fcmp ult float %x, 0.0
141 %b = select i1 %a, float %x, float 0.0
142 ret float %b
143}
144
145; CHECK-LABEL: fmax32:
146; CHECK: f32.max push, (get_local 1), (get_local 2){{$}}
147; CHECK-NEXT: set_local 3, pop{{$}}
148define float @fmax32(float %x) {
149 %a = fcmp ugt float %x, 0.0
150 %b = select i1 %a, float %x, float 0.0
151 ret float %b
152}