[llvm] 410e5b1 - [VE] Support fabs/fcos/fsin/fsqrt math functions

Kazushi Marukawa via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 15 14:27:46 PDT 2020


Author: Kazushi (Jam) Marukawa
Date: 2020-10-16T06:27:38+09:00
New Revision: 410e5b17cf11691de7775315dbf9d5e94f5c4808

URL: https://github.com/llvm/llvm-project/commit/410e5b17cf11691de7775315dbf9d5e94f5c4808
DIFF: https://github.com/llvm/llvm-project/commit/410e5b17cf11691de7775315dbf9d5e94f5c4808.diff

LOG: [VE] Support fabs/fcos/fsin/fsqrt math functions

VE doesn't have instruction for fabs/fcos/fsin/fsqrt, so expand them.
Add regression tests also.  Update fcopysign regression test, also.

Reviewed By: simoll

Differential Revision: https://reviews.llvm.org/D89457

Added: 
    llvm/test/CodeGen/VE/fabs.ll
    llvm/test/CodeGen/VE/fcopysign.ll
    llvm/test/CodeGen/VE/fcos.ll
    llvm/test/CodeGen/VE/fsin.ll
    llvm/test/CodeGen/VE/fsqrt.ll

Modified: 
    llvm/lib/Target/VE/VEISelLowering.cpp

Removed: 
    llvm/test/CodeGen/VE/fp_copysign.ll


################################################################################
diff  --git a/llvm/lib/Target/VE/VEISelLowering.cpp b/llvm/lib/Target/VE/VEISelLowering.cpp
index d165c348f2fab..150db3ab6446c 100644
--- a/llvm/lib/Target/VE/VEISelLowering.cpp
+++ b/llvm/lib/Target/VE/VEISelLowering.cpp
@@ -808,7 +808,11 @@ VETargetLowering::VETargetLowering(const TargetMachine &TM,
 
   // VE doesn't have following floating point math functions.
   for (MVT VT : MVT::fp_valuetypes()) {
+    setOperationAction(ISD::FABS, VT, Expand);
     setOperationAction(ISD::FCOPYSIGN, VT, Expand);
+    setOperationAction(ISD::FCOS, VT, Expand);
+    setOperationAction(ISD::FSIN, VT, Expand);
+    setOperationAction(ISD::FSQRT, VT, Expand);
   }
 
   /// } Floating-point math functions

diff  --git a/llvm/test/CodeGen/VE/fabs.ll b/llvm/test/CodeGen/VE/fabs.ll
new file mode 100644
index 0000000000000..3d76e5a1a4886
--- /dev/null
+++ b/llvm/test/CodeGen/VE/fabs.ll
@@ -0,0 +1,138 @@
+; RUN: llc < %s -mtriple=ve | FileCheck %s
+
+;;; Test ‘llvm.fabs.*’ Intrinsic
+;;;
+;;; Syntax:
+;;;   This is an overloaded intrinsic. You can use llvm.fabs on any
+;;;   floating-point or vector of floating-point type. Not all targets
+;;;   support all types however.
+;;;
+;;; declare float     @llvm.fabs.f32(float  %Val)
+;;; declare double    @llvm.fabs.f64(double %Val)
+;;; declare x86_fp80  @llvm.fabs.f80(x86_fp80 %Val)
+;;; declare fp128     @llvm.fabs.f128(fp128 %Val)
+;;; declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
+;;;
+;;; Overview:
+;;;   The ‘llvm.fabs.*’ intrinsics return the absolute value of the operand.
+;;;
+;;; Arguments:
+;;;   The argument and return value are floating-point numbers of the same
+;;;   type.
+;;;
+;;; Semantics:
+;;;   This function returns the same values as the libm fabs functions would,
+;;;   and handles error conditions in the same way.
+;;;
+;;; Note:
+;;;   We test only float/double/fp128.
+
+; Function Attrs: nounwind readnone
+define float @fabs_float_var(float %0) {
+; CHECK-LABEL: fabs_float_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    sra.l %s0, %s0, 32
+; CHECK-NEXT:    and %s0, %s0, (33)0
+; CHECK-NEXT:    sll %s0, %s0, 32
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast float @llvm.fabs.f32(float %0)
+  ret float %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare float @llvm.fabs.f32(float)
+
+; Function Attrs: nounwind readnone
+define double @fabs_double_var(double %0) {
+; CHECK-LABEL: fabs_double_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    and %s0, %s0, (1)0
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast double @llvm.fabs.f64(double %0)
+  ret double %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare double @llvm.fabs.f64(double)
+
+; Function Attrs: nounwind readnone
+define fp128 @fabs_quad_var(fp128 %0) {
+; CHECK-LABEL: fabs_quad_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    st %s1, 176(, %s11)
+; CHECK-NEXT:    st %s0, 184(, %s11)
+; CHECK-NEXT:    ld1b.zx %s0, 191(, %s11)
+; CHECK-NEXT:    and %s0, %s0, (57)0
+; CHECK-NEXT:    st1b %s0, 191(, %s11)
+; CHECK-NEXT:    ld %s1, 176(, %s11)
+; CHECK-NEXT:    ld %s0, 184(, %s11)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast fp128 @llvm.fabs.f128(fp128 %0)
+  ret fp128 %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare fp128 @llvm.fabs.f128(fp128)
+
+; Function Attrs: norecurse nounwind readnone
+define float @fabs_float_zero() {
+; CHECK-LABEL: fabs_float_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 0
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret float 0.000000e+00
+}
+
+; Function Attrs: norecurse nounwind readnone
+define double @fabs_double_zero() {
+; CHECK-LABEL: fabs_double_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 0
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret double 0.000000e+00
+}
+
+; Function Attrs: norecurse nounwind readnone
+define fp128 @fabs_quad_zero() {
+; CHECK-LABEL: fabs_quad_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0 at lo
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0 at hi(, %s0)
+; CHECK-NEXT:    ld %s0, 8(, %s2)
+; CHECK-NEXT:    ld %s1, (, %s2)
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret fp128 0xL00000000000000000000000000000000
+}
+
+; Function Attrs: norecurse nounwind readnone
+define float @fabs_float_const() {
+; CHECK-LABEL: fabs_float_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 1073741824
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret float 2.000000e+00
+}
+
+; Function Attrs: norecurse nounwind readnone
+define double @fabs_double_const() {
+; CHECK-LABEL: fabs_double_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 1073741824
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret double 2.000000e+00
+}
+
+; Function Attrs: nounwind readnone
+define fp128 @fabs_quad_const() {
+; CHECK-LABEL: fabs_quad_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0 at lo
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0 at hi(, %s0)
+; CHECK-NEXT:    ld %s0, 8(, %s2)
+; CHECK-NEXT:    ld %s1, (, %s2)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %1 = tail call fast fp128 @llvm.fabs.f128(fp128 0xL0000000000000000C000000000000000)
+  ret fp128 %1
+}

diff  --git a/llvm/test/CodeGen/VE/fp_copysign.ll b/llvm/test/CodeGen/VE/fcopysign.ll
similarity index 89%
rename from llvm/test/CodeGen/VE/fp_copysign.ll
rename to llvm/test/CodeGen/VE/fcopysign.ll
index 677e2b96abb42..98f5cd29c7789 100644
--- a/llvm/test/CodeGen/VE/fp_copysign.ll
+++ b/llvm/test/CodeGen/VE/fcopysign.ll
@@ -41,7 +41,7 @@ define float @copysign_float_var(float %0, float %1) {
 ; CHECK-NEXT:    or %s0, %s0, %s1
 ; CHECK-NEXT:    sll %s0, %s0, 32
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %3 = tail call float @llvm.copysign.f32(float %0, float %1)
+  %3 = tail call fast float @llvm.copysign.f32(float %0, float %1)
   ret float %3
 }
 
@@ -56,7 +56,7 @@ define double @copysign_double_var(double %0, double %1) {
 ; CHECK-NEXT:    and %s0, %s0, (1)0
 ; CHECK-NEXT:    or %s0, %s0, %s1
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %3 = tail call double @llvm.copysign.f64(double %0, double %1)
+  %3 = tail call fast double @llvm.copysign.f64(double %0, double %1)
   ret double %3
 }
 
@@ -81,7 +81,7 @@ define fp128 @copysign_quad_var(fp128 %0, fp128 %1) {
 ; CHECK-NEXT:    ld %s1, 176(, %s11)
 ; CHECK-NEXT:    ld %s0, 184(, %s11)
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %3 = tail call fp128 @llvm.copysign.f128(fp128 %0, fp128 %1)
+  %3 = tail call fast fp128 @llvm.copysign.f128(fp128 %0, fp128 %1)
   ret fp128 %3
 }
 
@@ -98,7 +98,7 @@ define float @copysign_float_zero(float %0) {
 ; CHECK-NEXT:    and %s0, %s0, %s1
 ; CHECK-NEXT:    sll %s0, %s0, 32
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %2 = tail call float @llvm.copysign.f32(float 0.000000e+00, float %0)
+  %2 = tail call fast float @llvm.copysign.f32(float 0.000000e+00, float %0)
   ret float %2
 }
 
@@ -108,7 +108,7 @@ define double @copysign_double_zero(double %0) {
 ; CHECK:       .LBB{{[0-9]+}}_2:
 ; CHECK-NEXT:    and %s0, %s0, (1)1
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %2 = tail call double @llvm.copysign.f64(double 0.000000e+00, double %0)
+  %2 = tail call fast double @llvm.copysign.f64(double 0.000000e+00, double %0)
   ret double %2
 }
 
@@ -135,7 +135,7 @@ define fp128 @copysign_quad_zero(fp128 %0) {
 ; CHECK-NEXT:    ld %s1, 176(, %s11)
 ; CHECK-NEXT:    ld %s0, 184(, %s11)
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %2 = tail call fp128 @llvm.copysign.f128(fp128 0xL00000000000000000000000000000000, fp128 %0)
+  %2 = tail call fast fp128 @llvm.copysign.f128(fp128 0xL00000000000000000000000000000000, fp128 %0)
   ret fp128 %2
 }
 
@@ -151,7 +151,7 @@ define float @copysign_float_const(float %0) {
 ; CHECK-NEXT:    or %s0, %s0, %s1
 ; CHECK-NEXT:    sll %s0, %s0, 32
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %2 = tail call float @llvm.copysign.f32(float -2.000000e+00, float %0)
+  %2 = tail call fast float @llvm.copysign.f32(float -2.000000e+00, float %0)
   ret float %2
 }
 
@@ -163,7 +163,7 @@ define double @copysign_double_const(double %0) {
 ; CHECK-NEXT:    lea.sl %s1, 1073741824
 ; CHECK-NEXT:    or %s0, %s0, %s1
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %2 = tail call double @llvm.copysign.f64(double -2.000000e+00, double %0)
+  %2 = tail call fast double @llvm.copysign.f64(double -2.000000e+00, double %0)
   ret double %2
 }
 
@@ -190,6 +190,6 @@ define fp128 @copysign_quad_const(fp128 %0) {
 ; CHECK-NEXT:    ld %s1, 176(, %s11)
 ; CHECK-NEXT:    ld %s0, 184(, %s11)
 ; CHECK-NEXT:    or %s11, 0, %s9
-  %2 = tail call fp128 @llvm.copysign.f128(fp128 0xL0000000000000000C000000000000000, fp128 %0)
+  %2 = tail call fast fp128 @llvm.copysign.f128(fp128 0xL0000000000000000C000000000000000, fp128 %0)
   ret fp128 %2
 }

diff  --git a/llvm/test/CodeGen/VE/fcos.ll b/llvm/test/CodeGen/VE/fcos.ll
new file mode 100644
index 0000000000000..f0bbeee8743a6
--- /dev/null
+++ b/llvm/test/CodeGen/VE/fcos.ll
@@ -0,0 +1,151 @@
+; RUN: llc < %s -mtriple=ve | FileCheck %s
+
+;;; Test ‘llvm.cos.*’ intrinsic
+;;;
+;;; Syntax:
+;;;   This is an overloaded intrinsic. You can use llvm.cos on any
+;;;   floating-point or vector of floating-point type. Not all targets
+;;;   support all types however.
+;;;
+;;; declare float     @llvm.cos.f32(float  %Val)
+;;; declare double    @llvm.cos.f64(double %Val)
+;;; declare x86_fp80  @llvm.cos.f80(x86_fp80  %Val)
+;;; declare fp128     @llvm.cos.f128(fp128 %Val)
+;;; declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128  %Val)
+;;;
+;;; Overview:
+;;;   The ‘llvm.cos.*’ intrinsics return the cosine of the operand.
+;;;
+;;; Arguments:
+;;;   The argument and return value are floating-point numbers of the same type.
+;;;
+;;; Semantics:
+;;;   Return the same value as a corresponding libm ‘cos’ function but without
+;;;   trapping or setting errno.
+;;;
+;;;   When specified with the fast-math-flag ‘afn’, the result may be
+;;;   approximated using a less accurate calculation.
+;;;
+;;; Note:
+;;;   We test only float/double/fp128.
+
+; Function Attrs: nounwind readnone
+define float @fcos_float_var(float %0) {
+; CHECK-LABEL: fcos_float_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s1, cosf at lo
+; CHECK-NEXT:    and %s1, %s1, (32)0
+; CHECK-NEXT:    lea.sl %s12, cosf at hi(, %s1)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast float @llvm.cos.f32(float %0)
+  ret float %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare float @llvm.cos.f32(float)
+
+; Function Attrs: nounwind readnone
+define double @fcos_double_var(double %0) {
+; CHECK-LABEL: fcos_double_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s1, cos at lo
+; CHECK-NEXT:    and %s1, %s1, (32)0
+; CHECK-NEXT:    lea.sl %s12, cos at hi(, %s1)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast double @llvm.cos.f64(double %0)
+  ret double %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare double @llvm.cos.f64(double)
+
+; Function Attrs: nounwind readnone
+define fp128 @fcos_quad_var(fp128 %0) {
+; CHECK-LABEL: fcos_quad_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s2, cosl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, cosl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast fp128 @llvm.cos.f128(fp128 %0)
+  ret fp128 %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare fp128 @llvm.cos.f128(fp128)
+
+; Function Attrs: norecurse nounwind readnone
+define float @fcos_float_zero() {
+; CHECK-LABEL: fcos_float_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 1065353216
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret float 1.000000e+00
+}
+
+; Function Attrs: norecurse nounwind readnone
+define double @fcos_double_zero() {
+; CHECK-LABEL: fcos_double_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 1072693248
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret double 1.000000e+00
+}
+
+; Function Attrs: nounwind readnone
+define fp128 @fcos_quad_zero() {
+; CHECK-LABEL: fcos_quad_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0 at lo
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0 at hi(, %s0)
+; CHECK-NEXT:    ld %s0, 8(, %s2)
+; CHECK-NEXT:    ld %s1, (, %s2)
+; CHECK-NEXT:    lea %s2, cosl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, cosl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %1 = tail call fast fp128 @llvm.cos.f128(fp128 0xL00000000000000000000000000000000)
+  ret fp128 %1
+}
+
+; Function Attrs: norecurse nounwind readnone
+define float @fcos_float_const() {
+; CHECK-LABEL: fcos_float_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, -1093332685
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret float 0xBFDAA22660000000
+}
+
+; Function Attrs: norecurse nounwind readnone
+define double @fcos_double_const() {
+; CHECK-LABEL: fcos_double_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, 1465086469
+; CHECK-NEXT:    lea.sl %s0, -1076190682(, %s0)
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret double 0xBFDAA22657537205
+}
+
+; Function Attrs: nounwind readnone
+define fp128 @fcos_quad_const() {
+; CHECK-LABEL: fcos_quad_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0 at lo
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0 at hi(, %s0)
+; CHECK-NEXT:    ld %s0, 8(, %s2)
+; CHECK-NEXT:    ld %s1, (, %s2)
+; CHECK-NEXT:    lea %s2, cosl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, cosl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %1 = tail call fast fp128 @llvm.cos.f128(fp128 0xL0000000000000000C000000000000000)
+  ret fp128 %1
+}

diff  --git a/llvm/test/CodeGen/VE/fsin.ll b/llvm/test/CodeGen/VE/fsin.ll
new file mode 100644
index 0000000000000..1a7faa17bab52
--- /dev/null
+++ b/llvm/test/CodeGen/VE/fsin.ll
@@ -0,0 +1,152 @@
+; RUN: llc < %s -mtriple=ve | FileCheck %s
+
+;;; Test ‘llvm.sin.*’ intrinsic
+;;;
+;;; Syntax:
+;;;   This is an overloaded intrinsic. You can use llvm.sin on any
+;;;   floating-point or vector of floating-point type. Not all targets
+;;;   support all types however.
+;;;
+;;; declare float     @llvm.sin.f32(float  %Val)
+;;; declare double    @llvm.sin.f64(double %Val)
+;;; declare x86_fp80  @llvm.sin.f80(x86_fp80  %Val)
+;;; declare fp128     @llvm.sin.f128(fp128 %Val)
+;;; declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128  %Val)
+;;;
+;;; Overview:
+;;;   The ‘llvm.sin.*’ intrinsics return the sine of the operand.
+;;;
+;;; Arguments:
+;;;   The argument and return value are floating-point numbers of the same type.
+;;;
+;;; Semantics:
+;;;   Return the same value as a corresponding libm ‘sin’ function but without
+;;;   trapping or setting errno.
+;;;
+;;;   When specified with the fast-math-flag ‘afn’, the result may be
+;;;   approximated using a less accurate calculation.
+;;;
+;;; Note:
+;;;   We test only float/double/fp128.
+
+; Function Attrs: nounwind readnone
+define float @fsin_float_var(float %0) {
+; CHECK-LABEL: fsin_float_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s1, sinf at lo
+; CHECK-NEXT:    and %s1, %s1, (32)0
+; CHECK-NEXT:    lea.sl %s12, sinf at hi(, %s1)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast float @llvm.sin.f32(float %0)
+  ret float %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare float @llvm.sin.f32(float)
+
+; Function Attrs: nounwind readnone
+define double @fsin_double_var(double %0) {
+; CHECK-LABEL: fsin_double_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s1, sin at lo
+; CHECK-NEXT:    and %s1, %s1, (32)0
+; CHECK-NEXT:    lea.sl %s12, sin at hi(, %s1)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast double @llvm.sin.f64(double %0)
+  ret double %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare double @llvm.sin.f64(double)
+
+; Function Attrs: nounwind readnone
+define fp128 @fsin_quad_var(fp128 %0) {
+; CHECK-LABEL: fsin_quad_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s2, sinl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, sinl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast fp128 @llvm.sin.f128(fp128 %0)
+  ret fp128 %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare fp128 @llvm.sin.f128(fp128)
+
+; Function Attrs: norecurse nounwind readnone
+define float @fsin_float_zero() {
+; CHECK-LABEL: fsin_float_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 0
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret float 0.000000e+00
+}
+
+; Function Attrs: norecurse nounwind readnone
+define double @fsin_double_zero() {
+; CHECK-LABEL: fsin_double_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 0
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret double 0.000000e+00
+}
+
+; Function Attrs: nounwind readnone
+define fp128 @fsin_quad_zero() {
+; CHECK-LABEL: fsin_quad_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0 at lo
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0 at hi(, %s0)
+; CHECK-NEXT:    ld %s0, 8(, %s2)
+; CHECK-NEXT:    ld %s1, (, %s2)
+; CHECK-NEXT:    lea %s2, sinl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, sinl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %1 = tail call fast fp128 @llvm.sin.f128(fp128 0xL00000000000000000000000000000000)
+  ret fp128 %1
+}
+
+; Function Attrs: norecurse nounwind readnone
+define float @fsin_float_const() {
+; CHECK-LABEL: fsin_float_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, -1083652169
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret float 0xBFED18F6E0000000
+}
+
+; Function Attrs: norecurse nounwind readnone
+define double @fsin_double_const() {
+; CHECK-LABEL: fsin_double_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, -355355578
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s0, -1074980618(, %s0)
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret double 0xBFED18F6EAD1B446
+}
+
+; Function Attrs: nounwind readnone
+define fp128 @fsin_quad_const() {
+; CHECK-LABEL: fsin_quad_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0 at lo
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0 at hi(, %s0)
+; CHECK-NEXT:    ld %s0, 8(, %s2)
+; CHECK-NEXT:    ld %s1, (, %s2)
+; CHECK-NEXT:    lea %s2, sinl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, sinl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %1 = tail call fast fp128 @llvm.sin.f128(fp128 0xL0000000000000000C000000000000000)
+  ret fp128 %1
+}

diff  --git a/llvm/test/CodeGen/VE/fsqrt.ll b/llvm/test/CodeGen/VE/fsqrt.ll
new file mode 100644
index 0000000000000..26abcce853ea7
--- /dev/null
+++ b/llvm/test/CodeGen/VE/fsqrt.ll
@@ -0,0 +1,151 @@
+; RUN: llc < %s -mtriple=ve | FileCheck %s
+
+;;; Test ‘llvm.sqrt.*’ intrinsic
+;;;
+;;; Syntax:
+;;;   This is an overloaded intrinsic. You can use llvm.sqrt on any
+;;;   floating-point or vector of floating-point type. Not all targets
+;;;   support all types however.
+;;;
+;;; declare float     @llvm.sqrt.f32(float %Val)
+;;; declare double    @llvm.sqrt.f64(double %Val)
+;;; declare x86_fp80  @llvm.sqrt.f80(x86_fp80 %Val)
+;;; declare fp128     @llvm.sqrt.f128(fp128 %Val)
+;;; declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
+;;;
+;;; Overview:
+;;;   The ‘llvm.sqrt’ intrinsics return the square root of the specified value.
+;;;
+;;; Arguments:
+;;;   The argument and return value are floating-point numbers of the same type.
+;;;
+;;; Semantics:
+;;;   Return the same value as a corresponding libm ‘sqrt’ function but without
+;;;   trapping or setting errno. For types specified by IEEE-754, the result
+;;;   matches a conforming libm implementation.
+;;;
+;;;   When specified with the fast-math-flag ‘afn’, the result may be
+;;;   approximated using a less accurate calculation.
+;;;
+;;; Note:
+;;;   We test only float/double/fp128.
+
+; Function Attrs: nounwind readnone
+define float @fsqrt_float_var(float %0) {
+; CHECK-LABEL: fsqrt_float_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s1, sqrtf at lo
+; CHECK-NEXT:    and %s1, %s1, (32)0
+; CHECK-NEXT:    lea.sl %s12, sqrtf at hi(, %s1)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast float @llvm.sqrt.f32(float %0)
+  ret float %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare float @llvm.sqrt.f32(float)
+
+; Function Attrs: nounwind readnone
+define double @fsqrt_double_var(double %0) {
+; CHECK-LABEL: fsqrt_double_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s1, sqrt at lo
+; CHECK-NEXT:    and %s1, %s1, (32)0
+; CHECK-NEXT:    lea.sl %s12, sqrt at hi(, %s1)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast double @llvm.sqrt.f64(double %0)
+  ret double %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare double @llvm.sqrt.f64(double)
+
+; Function Attrs: nounwind readnone
+define fp128 @fsqrt_quad_var(fp128 %0) {
+; CHECK-LABEL: fsqrt_quad_var:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s2, sqrtl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, sqrtl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %2 = tail call fast fp128 @llvm.sqrt.f128(fp128 %0)
+  ret fp128 %2
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare fp128 @llvm.sqrt.f128(fp128)
+
+; Function Attrs: norecurse nounwind readnone
+define float @fsqrt_float_zero() {
+; CHECK-LABEL: fsqrt_float_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 0
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret float 0.000000e+00
+}
+
+; Function Attrs: norecurse nounwind readnone
+define double @fsqrt_double_zero() {
+; CHECK-LABEL: fsqrt_double_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, 0
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret double 0.000000e+00
+}
+
+; Function Attrs: nounwind readnone
+define fp128 @fsqrt_quad_zero() {
+; CHECK-LABEL: fsqrt_quad_zero:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0 at lo
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0 at hi(, %s0)
+; CHECK-NEXT:    ld %s0, 8(, %s2)
+; CHECK-NEXT:    ld %s1, (, %s2)
+; CHECK-NEXT:    lea %s2, sqrtl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, sqrtl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %1 = tail call fast fp128 @llvm.sqrt.f128(fp128 0xL00000000000000000000000000000000)
+  ret fp128 %1
+}
+
+; Function Attrs: norecurse nounwind readnone
+define float @fsqrt_float_const() {
+; CHECK-LABEL: fsqrt_float_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, -4194304
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret float 0xFFF8000000000000
+}
+
+; Function Attrs: norecurse nounwind readnone
+define double @fsqrt_double_const() {
+; CHECK-LABEL: fsqrt_double_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea.sl %s0, -524288
+; CHECK-NEXT:    or %s11, 0, %s9
+  ret double 0xFFF8000000000000
+}
+
+; Function Attrs: nounwind readnone
+define fp128 @fsqrt_quad_const() {
+; CHECK-LABEL: fsqrt_quad_const:
+; CHECK:       .LBB{{[0-9]+}}_2:
+; CHECK-NEXT:    lea %s0, .LCPI{{[0-9]+}}_0 at lo
+; CHECK-NEXT:    and %s0, %s0, (32)0
+; CHECK-NEXT:    lea.sl %s2, .LCPI{{[0-9]+}}_0 at hi(, %s0)
+; CHECK-NEXT:    ld %s0, 8(, %s2)
+; CHECK-NEXT:    ld %s1, (, %s2)
+; CHECK-NEXT:    lea %s2, sqrtl at lo
+; CHECK-NEXT:    and %s2, %s2, (32)0
+; CHECK-NEXT:    lea.sl %s12, sqrtl at hi(, %s2)
+; CHECK-NEXT:    bsic %s10, (, %s12)
+; CHECK-NEXT:    or %s11, 0, %s9
+  %1 = tail call fast fp128 @llvm.sqrt.f128(fp128 0xL0000000000000000C000000000000000)
+  ret fp128 %1
+}


        


More information about the llvm-commits mailing list