Hi,
  This patch folds builtin_isinf on IBM long double to builtin_isinf on
its high-order double.

  The isinf_optab was already implemented in this patch.
https://gcc.gnu.org/g:53945be1efb502f235d84ff67ceafe4a764b6e1c

  Bootstrapped and tested on powerpc64-linux BE and LE with no
regressions. Is it OK for the trunk?

Thanks
Gui Haochen

ChangeLog
Builtins: Fold isinf on IBM long double to isinf on high-order double

For IBM long double, Inf is encoded in the high-order double value only.
So the builtin_isinf on IBM long double can be folded to builtin_isinf on
double type.  As former patch implemented DFmode isinf_optab, this patch
converts builtin_isinf on IBM long double to builtin_isinf on double type
if the DFmode isinf_optab exists.

gcc/
        PR target/97786
        * builtins.cc (fold_builtin_interclass_mathfn): Fold isinf on IBM
        long double to isinf on high_order double  when DFmode isinf_optab
        exists.

gcc/testsuite/
        PR target/97786
        * gcc.target/powerpc/pr97786-3.c: New test.

patch.diff
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 0b902896ddd..c20bd7b5f31 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -9568,6 +9568,15 @@ fold_builtin_interclass_mathfn (location_t loc, tree 
fndecl, tree arg)
            type = double_type_node;
            mode = DFmode;
            arg = fold_build1_loc (loc, NOP_EXPR, type, arg);
+
+           /* If isinf icode exists, build the call with high-order
+              double value only.  */
+           tree const isinf_fn = builtin_decl_explicit (BUILT_IN_ISINF);
+           if (interclass_mathfn_icode (arg, isinf_fn) != CODE_FOR_nothing)
+             {
+               result = build_call_expr (isinf_fn, 1, arg);
+               return result;
+             }
          }
        get_max_float (REAL_MODE_FORMAT (mode), buf, sizeof (buf), false);
        real_from_string (&r, buf);
diff --git a/gcc/testsuite/gcc.target/powerpc/pr97786-3.c 
b/gcc/testsuite/gcc.target/powerpc/pr97786-3.c
new file mode 100644
index 00000000000..6a8d9f2df53
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr97786-3.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target ppc_float128_hw } */
+/* { dg-options "-O2 -mdejagnu-cpu=power9 -mvsx -mabi=ibmlongdouble 
-Wno-psabi" } */
+/* { dg-require-effective-target powerpc_vsx } */
+
+int test1 (long double x)
+{
+  return __builtin_isinf (x);
+}
+
+int test2 (long double x)
+{
+  return __builtin_isinfl (x);
+}
+
+/* { dg-final { scan-assembler-not {\mfcmpu\M} } } */
+/* { dg-final { scan-assembler-times {\mxststdcdp\M} 2 } } */

Reply via email to