blob: a8842dbe33af403cbd672b605c8987d4454f928c [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 Gohmancf4748f2015-11-12 17:04:33 +000022; CHECK-NEXT: f32.add $push, (get_local 0), (get_local 1){{$}}
23; CHECK-NEXT: set_local 2, $pop{{$}}
24; CHECK-NEXT: return (get_local 2){{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000031; CHECK: f32.sub $push, (get_local 0), (get_local 1){{$}}
32; CHECK-NEXT: set_local 2, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000039; CHECK: f32.mul $push, (get_local 0), (get_local 1){{$}}
40; CHECK-NEXT: set_local 2, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000047; CHECK: f32.div $push, (get_local 0), (get_local 1){{$}}
48; CHECK-NEXT: set_local 2, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000055; CHECK: f32.abs $push, (get_local 0){{$}}
56; CHECK-NEXT: set_local 1, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000063; CHECK: f32.neg $push, (get_local 0){{$}}
64; CHECK-NEXT: set_local 1, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000071; CHECK: f32.copysign $push, (get_local 0), (get_local 1){{$}}
72; CHECK-NEXT: set_local 2, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000079; CHECK: f32.sqrt $push, (get_local 0){{$}}
80; CHECK-NEXT: set_local 1, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000087; CHECK: f32.ceil $push, (get_local 0){{$}}
88; CHECK-NEXT: set_local 1, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +000095; CHECK: f32.floor $push, (get_local 0){{$}}
96; CHECK-NEXT: set_local 1, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +0000103; CHECK: f32.trunc $push, (get_local 0){{$}}
104; CHECK-NEXT: set_local 1, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +0000111; CHECK: f32.nearest $push, (get_local 0){{$}}
112; CHECK-NEXT: set_local 1, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +0000119; CHECK: f32.nearest $push, (get_local 0){{$}}
120; CHECK-NEXT: set_local 1, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +0000133; CHECK: f32.min $push, (get_local 0), (get_local 1){{$}}
134; CHECK-NEXT: set_local 2, $pop{{$}}
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 Gohmancf4748f2015-11-12 17:04:33 +0000142; CHECK: f32.max $push, (get_local 0), (get_local 1){{$}}
143; CHECK-NEXT: set_local 2, $pop{{$}}
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}