blob: b709d6d919d68b9f19888203a7da94db951f6e76 [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:
Dan Gohman53828fd2015-11-23 16:50:18 +000018; CHECK-NEXT: .param f32, f32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000019; CHECK-NEXT: .result f32{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000020; CHECK-NEXT: f32.add $push0, $0, $1{{$}}
21; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000022define float @fadd32(float %x, float %y) {
23 %a = fadd float %x, %y
24 ret float %a
25}
26
Dan Gohmane51c0582015-10-06 00:27:55 +000027; CHECK-LABEL: fsub32:
Dan Gohman4ba48162015-11-18 16:12:01 +000028; CHECK: f32.sub $push0, $0, $1{{$}}
29; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000030define float @fsub32(float %x, float %y) {
31 %a = fsub float %x, %y
32 ret float %a
33}
34
Dan Gohmane51c0582015-10-06 00:27:55 +000035; CHECK-LABEL: fmul32:
Dan Gohman4ba48162015-11-18 16:12:01 +000036; CHECK: f32.mul $push0, $0, $1{{$}}
37; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000038define float @fmul32(float %x, float %y) {
39 %a = fmul float %x, %y
40 ret float %a
41}
42
Dan Gohmane51c0582015-10-06 00:27:55 +000043; CHECK-LABEL: fdiv32:
Dan Gohman4ba48162015-11-18 16:12:01 +000044; CHECK: f32.div $push0, $0, $1{{$}}
45; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000046define float @fdiv32(float %x, float %y) {
47 %a = fdiv float %x, %y
48 ret float %a
49}
50
Dan Gohmane51c0582015-10-06 00:27:55 +000051; CHECK-LABEL: fabs32:
Dan Gohman4ba48162015-11-18 16:12:01 +000052; CHECK: f32.abs $push0, $0{{$}}
53; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000054define float @fabs32(float %x) {
55 %a = call float @llvm.fabs.f32(float %x)
56 ret float %a
57}
58
Dan Gohmane51c0582015-10-06 00:27:55 +000059; CHECK-LABEL: fneg32:
Dan Gohman4ba48162015-11-18 16:12:01 +000060; CHECK: f32.neg $push0, $0{{$}}
61; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000062define float @fneg32(float %x) {
63 %a = fsub float -0., %x
64 ret float %a
65}
66
Dan Gohmane51c0582015-10-06 00:27:55 +000067; CHECK-LABEL: copysign32:
Dan Gohman4ba48162015-11-18 16:12:01 +000068; CHECK: f32.copysign $push0, $0, $1{{$}}
69; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000070define float @copysign32(float %x, float %y) {
71 %a = call float @llvm.copysign.f32(float %x, float %y)
72 ret float %a
73}
74
Dan Gohmane51c0582015-10-06 00:27:55 +000075; CHECK-LABEL: sqrt32:
Dan Gohman4ba48162015-11-18 16:12:01 +000076; CHECK: f32.sqrt $push0, $0{{$}}
77; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000078define float @sqrt32(float %x) {
79 %a = call float @llvm.sqrt.f32(float %x)
80 ret float %a
81}
Dan Gohman896e53f2015-08-24 18:23:13 +000082
Dan Gohmane51c0582015-10-06 00:27:55 +000083; CHECK-LABEL: ceil32:
Dan Gohman4ba48162015-11-18 16:12:01 +000084; CHECK: f32.ceil $push0, $0{{$}}
85; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000086define float @ceil32(float %x) {
87 %a = call float @llvm.ceil.f32(float %x)
88 ret float %a
89}
90
Dan Gohmane51c0582015-10-06 00:27:55 +000091; CHECK-LABEL: floor32:
Dan Gohman4ba48162015-11-18 16:12:01 +000092; CHECK: f32.floor $push0, $0{{$}}
93; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000094define float @floor32(float %x) {
95 %a = call float @llvm.floor.f32(float %x)
96 ret float %a
97}
98
Dan Gohmane51c0582015-10-06 00:27:55 +000099; CHECK-LABEL: trunc32:
Dan Gohman4ba48162015-11-18 16:12:01 +0000100; CHECK: f32.trunc $push0, $0{{$}}
101; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000102define float @trunc32(float %x) {
103 %a = call float @llvm.trunc.f32(float %x)
104 ret float %a
105}
106
Dan Gohmane51c0582015-10-06 00:27:55 +0000107; CHECK-LABEL: nearest32:
Dan Gohman4ba48162015-11-18 16:12:01 +0000108; CHECK: f32.nearest $push0, $0{{$}}
109; CHECK-NEXT: return $pop0{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000110define float @nearest32(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000111 %a = call float @llvm.nearbyint.f32(float %x)
112 ret float %a
113}
114
Dan Gohmane51c0582015-10-06 00:27:55 +0000115; CHECK-LABEL: nearest32_via_rint:
Dan Gohman4ba48162015-11-18 16:12:01 +0000116; CHECK: f32.nearest $push0, $0{{$}}
117; CHECK-NEXT: return $pop0{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000118define float @nearest32_via_rint(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000119 %a = call float @llvm.rint.f32(float %x)
120 ret float %a
121}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000122
123; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in
124; cases where there's a single fcmp with a select and it can prove that one
125; of the arms is never NaN, so we only test that case. In the future if LLVM
126; learns to form fminnan/fmaxnan in more cases, we can write more general
127; tests.
128
129; CHECK-LABEL: fmin32:
Dan Gohman4ba48162015-11-18 16:12:01 +0000130; CHECK: f32.min $push1, $0, $pop0{{$}}
131; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000132define float @fmin32(float %x) {
133 %a = fcmp ult float %x, 0.0
134 %b = select i1 %a, float %x, float 0.0
135 ret float %b
136}
137
138; CHECK-LABEL: fmax32:
Dan Gohman4ba48162015-11-18 16:12:01 +0000139; CHECK: f32.max $push1, $0, $pop0{{$}}
140; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000141define float @fmax32(float %x) {
142 %a = fcmp ugt float %x, 0.0
143 %b = select i1 %a, float %x, float 0.0
144 ret float %b
145}