1; RUN: llc < %s -mtriple=ve | FileCheck %s
2
3;;; Test ‘llvm.sqrt.*’ intrinsic
4;;;
5;;; Syntax:
6;;;   This is an overloaded intrinsic. You can use llvm.sqrt on any
7;;;   floating-point or vector of floating-point type. Not all targets
8;;;   support all types however.
9;;;
10;;; declare float     @llvm.sqrt.f32(float %Val)
11;;; declare double    @llvm.sqrt.f64(double %Val)
12;;; declare x86_fp80  @llvm.sqrt.f80(x86_fp80 %Val)
13;;; declare fp128     @llvm.sqrt.f128(fp128 %Val)
14;;; declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
15;;;
16;;; Overview:
17;;;   The ‘llvm.sqrt’ intrinsics return the square root of the specified value.
18;;;
19;;; Arguments:
20;;;   The argument and return value are floating-point numbers of the same type.
21;;;
22;;; Semantics:
23;;;   Return the same value as a corresponding libm ‘sqrt’ function but without
24;;;   trapping or setting errno. For types specified by IEEE-754, the result
25;;;   matches a conforming libm implementation.
26;;;
27;;;   When specified with the fast-math-flag ‘afn’, the result may be
28;;;   approximated using a less accurate calculation.
29;;;
30;;; Note:
31;;;   We test only float/double/fp128.
32
33; Function Attrs: nounwind readnone
34define float @fsqrt_float_var(float %0) {
35; CHECK-LABEL: fsqrt_float_var:
36; CHECK:       .LBB{{[0-9]+}}_2:
37; CHECK-NEXT:    lea %s1, sqrtf@lo
38; CHECK-NEXT:    and %s1, %s1, (32)0
39; CHECK-NEXT:    lea.sl %s12, sqrtf@hi(, %s1)
40; CHECK-NEXT:    bsic %s10, (, %s12)
41; CHECK-NEXT:    or %s11, 0, %s9
42  %2 = tail call fast float @llvm.sqrt.f32(float %0)
43  ret float %2
44}
45
46; Function Attrs: nounwind readnone speculatable willreturn
47declare float @llvm.sqrt.f32(float)
48
49; Function Attrs: nounwind readnone
50define double @fsqrt_double_var(double %0) {
51; CHECK-LABEL: fsqrt_double_var:
52; CHECK:       .LBB{{[0-9]+}}_2:
53; CHECK-NEXT:    lea %s1, sqrt@lo
54; CHECK-NEXT:    and %s1, %s1, (32)0
55; CHECK-NEXT:    lea.sl %s12, sqrt@hi(, %s1)
56; CHECK-NEXT:    bsic %s10, (, %s12)
57; CHECK-NEXT:    or %s11, 0, %s9
58  %2 = tail call fast double @llvm.sqrt.f64(double %0)
59  ret double %2
60}
61
62; Function Attrs: nounwind readnone speculatable willreturn
63declare double @llvm.sqrt.f64(double)
64
65; Function Attrs: nounwind readnone
66define fp128 @fsqrt_quad_var(fp128 %0) {
67; CHECK-LABEL: fsqrt_quad_var:
68; CHECK:       .LBB{{[0-9]+}}_2:
69; CHECK-NEXT:    lea %s2, sqrtl@lo
70; CHECK-NEXT:    and %s2, %s2, (32)0
71; CHECK-NEXT:    lea.sl %s12, sqrtl@hi(, %s2)
72; CHECK-NEXT:    bsic %s10, (, %s12)
73; CHECK-NEXT:    or %s11, 0, %s9
74  %2 = tail call fast fp128 @llvm.sqrt.f128(fp128 %0)
75  ret fp128 %2
76}
77
78; Function Attrs: nounwind readnone speculatable willreturn
79declare fp128 @llvm.sqrt.f128(fp128)
80
81; Function Attrs: norecurse nounwind readnone
82define float @fsqrt_float_zero() {
83; CHECK-LABEL: fsqrt_float_zero:
84; CHECK:       # %bb.0:
85; CHECK-NEXT:    lea.sl %s0, 0
86; CHECK-NEXT:    b.l.t (, %s10)
87  ret float 0.000000e+00
88}
89
90; Function Attrs: norecurse nounwind readnone
91define double @fsqrt_double_zero() {
92; CHECK-LABEL: fsqrt_double_zero:
93; CHECK:       # %bb.0:
94; CHECK-NEXT:    lea.sl %s0, 0
95; CHECK-NEXT:    b.l.t (, %s10)
96  ret double 0.000000e+00
97}
98
99; Function Attrs: nounwind readnone
100define fp128 @fsqrt_quad_zero() {
101; CHECK-LABEL: fsqrt_quad_zero:
102; CHECK:       .LBB{{[0-9]+}}_2:
103; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0@lo
104; CHECK-NEXT:    and %s0, %s0, (32)0
105; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0@hi(, %s0)
106; CHECK-NEXT:    ld %s0, 8(, %s2)
107; CHECK-NEXT:    ld %s1, (, %s2)
108; CHECK-NEXT:    lea %s2, sqrtl@lo
109; CHECK-NEXT:    and %s2, %s2, (32)0
110; CHECK-NEXT:    lea.sl %s12, sqrtl@hi(, %s2)
111; CHECK-NEXT:    bsic %s10, (, %s12)
112; CHECK-NEXT:    or %s11, 0, %s9
113  %1 = tail call fast fp128 @llvm.sqrt.f128(fp128 0xL00000000000000000000000000000000)
114  ret fp128 %1
115}
116
117; Function Attrs: norecurse nounwind readnone
118define float @fsqrt_float_const() {
119; CHECK-LABEL: fsqrt_float_const:
120; CHECK:       # %bb.0:
121; CHECK-NEXT:    lea.sl %s0, -4194304
122; CHECK-NEXT:    b.l.t (, %s10)
123  ret float 0xFFF8000000000000
124}
125
126; Function Attrs: norecurse nounwind readnone
127define double @fsqrt_double_const() {
128; CHECK-LABEL: fsqrt_double_const:
129; CHECK:       # %bb.0:
130; CHECK-NEXT:    lea.sl %s0, -524288
131; CHECK-NEXT:    b.l.t (, %s10)
132  ret double 0xFFF8000000000000
133}
134
135; Function Attrs: nounwind readnone
136define fp128 @fsqrt_quad_const() {
137; CHECK-LABEL: fsqrt_quad_const:
138; CHECK:       .LBB{{[0-9]+}}_2:
139; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0@lo
140; CHECK-NEXT:    and %s0, %s0, (32)0
141; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0@hi(, %s0)
142; CHECK-NEXT:    ld %s0, 8(, %s2)
143; CHECK-NEXT:    ld %s1, (, %s2)
144; CHECK-NEXT:    lea %s2, sqrtl@lo
145; CHECK-NEXT:    and %s2, %s2, (32)0
146; CHECK-NEXT:    lea.sl %s12, sqrtl@hi(, %s2)
147; CHECK-NEXT:    bsic %s10, (, %s12)
148; CHECK-NEXT:    or %s11, 0, %s9
149  %1 = tail call fast fp128 @llvm.sqrt.f128(fp128 0xL0000000000000000C000000000000000)
150  ret fp128 %1
151}
152