1 ; RUN: llc < %s -mtriple=ve | FileCheck %s
3 ;;; Test ‘llvm.sqrt.*’ intrinsic
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.
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)
17 ;;; The ‘llvm.sqrt’ intrinsics return the square root of the specified value.
20 ;;; The argument and return value are floating-point numbers of the same type.
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.
27 ;;; When specified with the fast-math-flag ‘afn’, the result may be
28 ;;; approximated using a less accurate calculation.
31 ;;; We test only float/double/fp128.
33 ; Function Attrs: nounwind readnone
34 define 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)
46 ; Function Attrs: nounwind readnone speculatable willreturn
47 declare float @llvm.sqrt.f32(float)
49 ; Function Attrs: nounwind readnone
50 define 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)
62 ; Function Attrs: nounwind readnone speculatable willreturn
63 declare double @llvm.sqrt.f64(double)
65 ; Function Attrs: nounwind readnone
66 define 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)
78 ; Function Attrs: nounwind readnone speculatable willreturn
79 declare fp128 @llvm.sqrt.f128(fp128)
81 ; Function Attrs: norecurse nounwind readnone
82 define float @fsqrt_float_zero() {
83 ; CHECK-LABEL: fsqrt_float_zero:
85 ; CHECK-NEXT: lea.sl %s0, 0
86 ; CHECK-NEXT: b.l.t (, %s10)
87 ret float 0.000000e+00
90 ; Function Attrs: norecurse nounwind readnone
91 define double @fsqrt_double_zero() {
92 ; CHECK-LABEL: fsqrt_double_zero:
94 ; CHECK-NEXT: lea.sl %s0, 0
95 ; CHECK-NEXT: b.l.t (, %s10)
96 ret double 0.000000e+00
99 ; Function Attrs: nounwind readnone
100 define 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)
117 ; Function Attrs: norecurse nounwind readnone
118 define float @fsqrt_float_const() {
119 ; CHECK-LABEL: fsqrt_float_const:
121 ; CHECK-NEXT: lea.sl %s0, -4194304
122 ; CHECK-NEXT: b.l.t (, %s10)
123 ret float 0xFFF8000000000000
126 ; Function Attrs: norecurse nounwind readnone
127 define double @fsqrt_double_const() {
128 ; CHECK-LABEL: fsqrt_double_const:
130 ; CHECK-NEXT: lea.sl %s0, -524288
131 ; CHECK-NEXT: b.l.t (, %s10)
132 ret double 0xFFF8000000000000
135 ; Function Attrs: nounwind readnone
136 define 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)