blob: 25d057e8958c4a5f420e110dd9dff07699f15548 [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 Gohman0c6f5ac2016-01-07 03:19:23 +00005target datalayout = "e-m: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)
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 Gohman700515f2015-11-23 21:55:57 +000021; CHECK-NEXT: f32.add $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000022; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000023define float @fadd32(float %x, float %y) {
24 %a = fadd float %x, %y
25 ret float %a
26}
27
Dan Gohmane51c0582015-10-06 00:27:55 +000028; CHECK-LABEL: fsub32:
Dan Gohman700515f2015-11-23 21:55:57 +000029; CHECK: f32.sub $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000030; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000031define float @fsub32(float %x, float %y) {
32 %a = fsub float %x, %y
33 ret float %a
34}
35
Dan Gohmane51c0582015-10-06 00:27:55 +000036; CHECK-LABEL: fmul32:
Dan Gohman700515f2015-11-23 21:55:57 +000037; CHECK: f32.mul $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000038; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000039define float @fmul32(float %x, float %y) {
40 %a = fmul float %x, %y
41 ret float %a
42}
43
Dan Gohmane51c0582015-10-06 00:27:55 +000044; CHECK-LABEL: fdiv32:
Dan Gohman700515f2015-11-23 21:55:57 +000045; CHECK: f32.div $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000046; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000047define float @fdiv32(float %x, float %y) {
48 %a = fdiv float %x, %y
49 ret float %a
50}
51
Dan Gohmane51c0582015-10-06 00:27:55 +000052; CHECK-LABEL: fabs32:
Dan Gohman700515f2015-11-23 21:55:57 +000053; CHECK: f32.abs $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000054; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000055define float @fabs32(float %x) {
56 %a = call float @llvm.fabs.f32(float %x)
57 ret float %a
58}
59
Dan Gohmane51c0582015-10-06 00:27:55 +000060; CHECK-LABEL: fneg32:
Dan Gohman700515f2015-11-23 21:55:57 +000061; CHECK: f32.neg $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000062; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000063define float @fneg32(float %x) {
64 %a = fsub float -0., %x
65 ret float %a
66}
67
Dan Gohmane51c0582015-10-06 00:27:55 +000068; CHECK-LABEL: copysign32:
Dan Gohman700515f2015-11-23 21:55:57 +000069; CHECK: f32.copysign $push0=, $0, $1{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000070; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000071define float @copysign32(float %x, float %y) {
72 %a = call float @llvm.copysign.f32(float %x, float %y)
73 ret float %a
74}
75
Dan Gohmane51c0582015-10-06 00:27:55 +000076; CHECK-LABEL: sqrt32:
Dan Gohman700515f2015-11-23 21:55:57 +000077; CHECK: f32.sqrt $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000078; CHECK-NEXT: return $pop0{{$}}
JF Bastienef172fc2015-08-11 02:45:15 +000079define float @sqrt32(float %x) {
80 %a = call float @llvm.sqrt.f32(float %x)
81 ret float %a
82}
Dan Gohman896e53f2015-08-24 18:23:13 +000083
Dan Gohmane51c0582015-10-06 00:27:55 +000084; CHECK-LABEL: ceil32:
Dan Gohman700515f2015-11-23 21:55:57 +000085; CHECK: f32.ceil $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000086; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000087define float @ceil32(float %x) {
88 %a = call float @llvm.ceil.f32(float %x)
89 ret float %a
90}
91
Dan Gohmane51c0582015-10-06 00:27:55 +000092; CHECK-LABEL: floor32:
Dan Gohman700515f2015-11-23 21:55:57 +000093; CHECK: f32.floor $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000094; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +000095define float @floor32(float %x) {
96 %a = call float @llvm.floor.f32(float %x)
97 ret float %a
98}
99
Dan Gohmane51c0582015-10-06 00:27:55 +0000100; CHECK-LABEL: trunc32:
Dan Gohman700515f2015-11-23 21:55:57 +0000101; CHECK: f32.trunc $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000102; CHECK-NEXT: return $pop0{{$}}
Dan Gohman896e53f2015-08-24 18:23:13 +0000103define float @trunc32(float %x) {
104 %a = call float @llvm.trunc.f32(float %x)
105 ret float %a
106}
107
Dan Gohmane51c0582015-10-06 00:27:55 +0000108; CHECK-LABEL: nearest32:
Dan Gohman700515f2015-11-23 21:55:57 +0000109; CHECK: f32.nearest $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000110; CHECK-NEXT: return $pop0{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000111define float @nearest32(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000112 %a = call float @llvm.nearbyint.f32(float %x)
113 ret float %a
114}
115
Dan Gohmane51c0582015-10-06 00:27:55 +0000116; CHECK-LABEL: nearest32_via_rint:
Dan Gohman700515f2015-11-23 21:55:57 +0000117; CHECK: f32.nearest $push0=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000118; CHECK-NEXT: return $pop0{{$}}
Dan Gohmand0bf9812015-09-26 01:09:44 +0000119define float @nearest32_via_rint(float %x) {
Dan Gohman896e53f2015-08-24 18:23:13 +0000120 %a = call float @llvm.rint.f32(float %x)
121 ret float %a
122}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000123
124; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in
125; cases where there's a single fcmp with a select and it can prove that one
126; of the arms is never NaN, so we only test that case. In the future if LLVM
127; learns to form fminnan/fmaxnan in more cases, we can write more general
128; tests.
129
130; CHECK-LABEL: fmin32:
Dan Gohman700515f2015-11-23 21:55:57 +0000131; CHECK: f32.min $push1=, $0, $pop0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000132; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000133define float @fmin32(float %x) {
134 %a = fcmp ult float %x, 0.0
135 %b = select i1 %a, float %x, float 0.0
136 ret float %b
137}
138
139; CHECK-LABEL: fmax32:
Dan Gohman700515f2015-11-23 21:55:57 +0000140; CHECK: f32.max $push1=, $0, $pop0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000141; CHECK-NEXT: return $pop1{{$}}
Dan Gohmanb84ae9b2015-11-10 21:40:21 +0000142define float @fmax32(float %x) {
143 %a = fcmp ugt float %x, 0.0
144 %b = select i1 %a, float %x, float 0.0
145 ret float %b
146}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000147
148; CHECK-LABEL: fma32:
Dan Gohmanc7c04452015-12-14 22:56:51 +0000149; CHECK: {{^}} f32.call $push0=, fmaf, $0, $1, $2{{$}}
Dan Gohman9341c1d2015-12-10 04:52:33 +0000150; CHECK-NEXT: return $pop0{{$}}
151define float @fma32(float %a, float %b, float %c) {
152 %d = call float @llvm.fma.f32(float %a, float %b, float %c)
153 ret float %d
154}