1; RUN: llc < %s -mtriple=ve | FileCheck %s
2
3;;; Test ‘llvm.fabs.*’ Intrinsic
4;;;
5;;; Syntax:
6;;;   This is an overloaded intrinsic. You can use llvm.fabs on any
7;;;   floating-point or vector of floating-point type. Not all targets
8;;;   support all types however.
9;;;
10;;; declare float     @llvm.fabs.f32(float  %Val)
11;;; declare double    @llvm.fabs.f64(double %Val)
12;;; declare x86_fp80  @llvm.fabs.f80(x86_fp80 %Val)
13;;; declare fp128     @llvm.fabs.f128(fp128 %Val)
14;;; declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
15;;;
16;;; Overview:
17;;;   The ‘llvm.fabs.*’ intrinsics return the absolute value of the operand.
18;;;
19;;; Arguments:
20;;;   The argument and return value are floating-point numbers of the same
21;;;   type.
22;;;
23;;; Semantics:
24;;;   This function returns the same values as the libm fabs functions would,
25;;;   and handles error conditions in the same way.
26;;;
27;;; Note:
28;;;   We test only float/double/fp128.
29
30; Function Attrs: nounwind readnone
31define float @fabs_float_var(float %0) {
32; CHECK-LABEL: fabs_float_var:
33; CHECK:       # %bb.0:
34; CHECK-NEXT:    sra.l %s0, %s0, 32
35; CHECK-NEXT:    and %s0, %s0, (33)0
36; CHECK-NEXT:    sll %s0, %s0, 32
37; CHECK-NEXT:    b.l.t (, %s10)
38  %2 = tail call fast float @llvm.fabs.f32(float %0)
39  ret float %2
40}
41
42; Function Attrs: nounwind readnone speculatable willreturn
43declare float @llvm.fabs.f32(float)
44
45; Function Attrs: nounwind readnone
46define double @fabs_double_var(double %0) {
47; CHECK-LABEL: fabs_double_var:
48; CHECK:       # %bb.0:
49; CHECK-NEXT:    and %s0, %s0, (1)0
50; CHECK-NEXT:    b.l.t (, %s10)
51  %2 = tail call fast double @llvm.fabs.f64(double %0)
52  ret double %2
53}
54
55; Function Attrs: nounwind readnone speculatable willreturn
56declare double @llvm.fabs.f64(double)
57
58; Function Attrs: nounwind readnone
59define fp128 @fabs_quad_var(fp128 %0) {
60; CHECK-LABEL: fabs_quad_var:
61; CHECK:       .LBB{{[0-9]+}}_2:
62; CHECK-NEXT:    st %s1, (, %s11)
63; CHECK-NEXT:    st %s0, 8(, %s11)
64; CHECK-NEXT:    ld1b.zx %s0, 15(, %s11)
65; CHECK-NEXT:    and %s0, %s0, (57)0
66; CHECK-NEXT:    st1b %s0, 15(, %s11)
67; CHECK-NEXT:    ld %s1, (, %s11)
68; CHECK-NEXT:    ld %s0, 8(, %s11)
69; CHECK-NEXT:    adds.l %s11, 16, %s11
70; CHECK-NEXT:    b.l.t (, %s10)
71  %2 = tail call fast fp128 @llvm.fabs.f128(fp128 %0)
72  ret fp128 %2
73}
74
75; Function Attrs: nounwind readnone speculatable willreturn
76declare fp128 @llvm.fabs.f128(fp128)
77
78; Function Attrs: norecurse nounwind readnone
79define float @fabs_float_zero() {
80; CHECK-LABEL: fabs_float_zero:
81; CHECK:       # %bb.0:
82; CHECK-NEXT:    lea.sl %s0, 0
83; CHECK-NEXT:    b.l.t (, %s10)
84  ret float 0.000000e+00
85}
86
87; Function Attrs: norecurse nounwind readnone
88define double @fabs_double_zero() {
89; CHECK-LABEL: fabs_double_zero:
90; CHECK:       # %bb.0:
91; CHECK-NEXT:    lea.sl %s0, 0
92; CHECK-NEXT:    b.l.t (, %s10)
93  ret double 0.000000e+00
94}
95
96; Function Attrs: norecurse nounwind readnone
97define fp128 @fabs_quad_zero() {
98; CHECK-LABEL: fabs_quad_zero:
99; CHECK:       # %bb.0:
100; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0@lo
101; CHECK-NEXT:    and %s0, %s0, (32)0
102; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0@hi(, %s0)
103; CHECK-NEXT:    ld %s0, 8(, %s2)
104; CHECK-NEXT:    ld %s1, (, %s2)
105; CHECK-NEXT:    b.l.t (, %s10)
106  ret fp128 0xL00000000000000000000000000000000
107}
108
109; Function Attrs: norecurse nounwind readnone
110define float @fabs_float_const() {
111; CHECK-LABEL: fabs_float_const:
112; CHECK:       # %bb.0:
113; CHECK-NEXT:    lea.sl %s0, 1073741824
114; CHECK-NEXT:    b.l.t (, %s10)
115  ret float 2.000000e+00
116}
117
118; Function Attrs: norecurse nounwind readnone
119define double @fabs_double_const() {
120; CHECK-LABEL: fabs_double_const:
121; CHECK:       # %bb.0:
122; CHECK-NEXT:    lea.sl %s0, 1073741824
123; CHECK-NEXT:    b.l.t (, %s10)
124  ret double 2.000000e+00
125}
126
127; Function Attrs: nounwind readnone
128define fp128 @fabs_quad_const() {
129; CHECK-LABEL: fabs_quad_const:
130; CHECK:       # %bb.0:
131; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0@lo
132; CHECK-NEXT:    and %s0, %s0, (32)0
133; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0@hi(, %s0)
134; CHECK-NEXT:    ld %s0, 8(, %s2)
135; CHECK-NEXT:    ld %s1, (, %s2)
136; CHECK-NEXT:    b.l.t (, %s10)
137  %1 = tail call fast fp128 @llvm.fabs.f128(fp128 0xL0000000000000000C000000000000000)
138  ret fp128 %1
139}
140