• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt | FileCheck %s
2
3; Test that basic 32-bit floating-point operations assemble as expected.
4
5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6target triple = "wasm32-unknown-unknown"
7
8declare float @llvm.fabs.f32(float)
9declare float @llvm.copysign.f32(float, float)
10declare float @llvm.sqrt.f32(float)
11declare 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)
16declare float @llvm.fma.f32(float, float, float)
17
18; CHECK-LABEL: fadd32:
19; CHECK-NEXT: .param f32, f32{{$}}
20; CHECK-NEXT: .result f32{{$}}
21; CHECK-NEXT: f32.add $push0=, $0, $1{{$}}
22; CHECK-NEXT: return $pop0{{$}}
23define float @fadd32(float %x, float %y) {
24  %a = fadd float %x, %y
25  ret float %a
26}
27
28; CHECK-LABEL: fsub32:
29; CHECK: f32.sub $push0=, $0, $1{{$}}
30; CHECK-NEXT: return $pop0{{$}}
31define float @fsub32(float %x, float %y) {
32  %a = fsub float %x, %y
33  ret float %a
34}
35
36; CHECK-LABEL: fmul32:
37; CHECK: f32.mul $push0=, $0, $1{{$}}
38; CHECK-NEXT: return $pop0{{$}}
39define float @fmul32(float %x, float %y) {
40  %a = fmul float %x, %y
41  ret float %a
42}
43
44; CHECK-LABEL: fdiv32:
45; CHECK: f32.div $push0=, $0, $1{{$}}
46; CHECK-NEXT: return $pop0{{$}}
47define float @fdiv32(float %x, float %y) {
48  %a = fdiv float %x, %y
49  ret float %a
50}
51
52; CHECK-LABEL: fabs32:
53; CHECK: f32.abs $push0=, $0{{$}}
54; CHECK-NEXT: return $pop0{{$}}
55define float @fabs32(float %x) {
56  %a = call float @llvm.fabs.f32(float %x)
57  ret float %a
58}
59
60; CHECK-LABEL: fneg32:
61; CHECK: f32.neg $push0=, $0{{$}}
62; CHECK-NEXT: return $pop0{{$}}
63define float @fneg32(float %x) {
64  %a = fsub float -0., %x
65  ret float %a
66}
67
68; CHECK-LABEL: copysign32:
69; CHECK: f32.copysign $push0=, $0, $1{{$}}
70; CHECK-NEXT: return $pop0{{$}}
71define float @copysign32(float %x, float %y) {
72  %a = call float @llvm.copysign.f32(float %x, float %y)
73  ret float %a
74}
75
76; CHECK-LABEL: sqrt32:
77; CHECK: f32.sqrt $push0=, $0{{$}}
78; CHECK-NEXT: return $pop0{{$}}
79define float @sqrt32(float %x) {
80  %a = call float @llvm.sqrt.f32(float %x)
81  ret float %a
82}
83
84; CHECK-LABEL: ceil32:
85; CHECK: f32.ceil $push0=, $0{{$}}
86; CHECK-NEXT: return $pop0{{$}}
87define float @ceil32(float %x) {
88  %a = call float @llvm.ceil.f32(float %x)
89  ret float %a
90}
91
92; CHECK-LABEL: floor32:
93; CHECK: f32.floor $push0=, $0{{$}}
94; CHECK-NEXT: return $pop0{{$}}
95define float @floor32(float %x) {
96  %a = call float @llvm.floor.f32(float %x)
97  ret float %a
98}
99
100; CHECK-LABEL: trunc32:
101; CHECK: f32.trunc $push0=, $0{{$}}
102; CHECK-NEXT: return $pop0{{$}}
103define float @trunc32(float %x) {
104  %a = call float @llvm.trunc.f32(float %x)
105  ret float %a
106}
107
108; CHECK-LABEL: nearest32:
109; CHECK: f32.nearest $push0=, $0{{$}}
110; CHECK-NEXT: return $pop0{{$}}
111define float @nearest32(float %x) {
112  %a = call float @llvm.nearbyint.f32(float %x)
113  ret float %a
114}
115
116; CHECK-LABEL: nearest32_via_rint:
117; CHECK: f32.nearest $push0=, $0{{$}}
118; CHECK-NEXT: return $pop0{{$}}
119define float @nearest32_via_rint(float %x) {
120  %a = call float @llvm.rint.f32(float %x)
121  ret float %a
122}
123
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:
131; CHECK: f32.min $push1=, $0, $pop0{{$}}
132; CHECK-NEXT: return $pop1{{$}}
133define 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:
140; CHECK: f32.max $push1=, $0, $pop0{{$}}
141; CHECK-NEXT: return $pop1{{$}}
142define 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}
147
148; CHECK-LABEL: fma32:
149; CHECK: {{^}} f32.call $push0=, fmaf@FUNCTION, $0, $1, $2{{$}}
150; 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}
155