public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>,
	Jeff Law <jeffreyalaw@gmail.com>,
	"Joseph S. Myers" <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] cdce: Fix up get_no_error_domain for new f{16,32,64,128} builtins [PR107547]
Date: Tue, 8 Nov 2022 12:01:53 +0100	[thread overview]
Message-ID: <Y2o3IekL8TZKHdlR@tucnak> (raw)

Hi!

I've missed that this function needs to handle all the builtins that
are handled in can_test_argument_range.
The following patch does that.  For many of the builtins (like acos, or
log) it is the same range regardless of the floating point type, but for
some (cosh, sinh, exp{,m1,2}) it is different for each format,
so I had to compute those ranges.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Note, seems the existing ranges were in some cases (e.g. for exp2)
the smallest in absolute value which results infinite result, in others
the largest which still results in finite result (but consistently so
for the IEEE single vs. double).  I've followed that for IEEE half and
quad cases too, just am not sure why it was like that.  I think
get_domain with true, false is open interval rather than closed
and the comments indicate that too, conservatively that is certainly
correct.

OT, with frange, perhaps we could DCE the calls unconditionally if
frange can prove we are in the domain range.

2022-11-08  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/107547
	* tree-call-cdce.cc (get_no_error_domain): Handle CASE_FLT_FN_FLOATN_NX
	of BUILT_IN_{ACOS,ASIN,ACOSH,ATANH,LOG,LOG2,LOG10,LOG1P}.  Handle
	BUILT_IN_{COSH,SINH,EXP,EXPM1,EXP2}F{16,32,64,128}.

	* gcc.dg/pr107547.c: New test.

--- gcc/tree-call-cdce.cc.jj	2022-10-31 09:04:56.484075098 +0100
+++ gcc/tree-call-cdce.cc	2022-11-07 14:51:54.223803618 +0100
@@ -693,20 +693,31 @@ get_no_error_domain (enum built_in_funct
     {
     /* Trig functions: return [-1, +1]  */
     CASE_FLT_FN (BUILT_IN_ACOS):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_ACOS):
     CASE_FLT_FN (BUILT_IN_ASIN):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_ASIN):
       return get_domain (-1, true, true,
                          1, true, true);
     /* Hyperbolic functions.  */
     CASE_FLT_FN (BUILT_IN_ACOSH):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_ACOSH):
       /* acosh: [1, +inf)  */
       return get_domain (1, true, true,
                          1, false, false);
     CASE_FLT_FN (BUILT_IN_ATANH):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_ATANH):
       /* atanh: (-1, +1)  */
       return get_domain (-1, true, false,
                          1, true, false);
+    case BUILT_IN_COSHF16:
+    case BUILT_IN_SINHF16:
+      /* coshf16: (-11, +11)  */
+      return get_domain (-11, true, false,
+			 11, true, false);
     case BUILT_IN_COSHF:
     case BUILT_IN_SINHF:
+    case BUILT_IN_COSHF32:
+    case BUILT_IN_SINHF32:
       /* coshf: (-89, +89)  */
       return get_domain (-89, true, false,
                          89, true, false);
@@ -714,21 +725,39 @@ get_no_error_domain (enum built_in_funct
     case BUILT_IN_SINH:
     case BUILT_IN_COSHL:
     case BUILT_IN_SINHL:
+    case BUILT_IN_COSHF64:
+    case BUILT_IN_SINHF64:
       /* cosh: (-710, +710)  */
       return get_domain (-710, true, false,
                          710, true, false);
+    case BUILT_IN_COSHF128:
+    case BUILT_IN_SINHF128:
+      /* coshf128: (-11357, +11357)  */
+      return get_domain (-11357, true, false,
+			 11357, true, false);
     /* Log functions: (0, +inf)  */
     CASE_FLT_FN (BUILT_IN_LOG):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG):
     CASE_FLT_FN (BUILT_IN_LOG2):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG2):
     CASE_FLT_FN (BUILT_IN_LOG10):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG10):
       return get_domain (0, true, false,
                          0, false, false);
     CASE_FLT_FN (BUILT_IN_LOG1P):
+    CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG1P):
       return get_domain (-1, true, false,
                          0, false, false);
     /* Exp functions.  */
+    case BUILT_IN_EXPF16:
+    case BUILT_IN_EXPM1F16:
+      /* expf: (-inf, 11)  */
+      return get_domain (-1, false, false,
+			 11, true, false);
     case BUILT_IN_EXPF:
     case BUILT_IN_EXPM1F:
+    case BUILT_IN_EXPF32:
+    case BUILT_IN_EXPM1F32:
       /* expf: (-inf, 88)  */
       return get_domain (-1, false, false,
                          88, true, false);
@@ -736,18 +765,35 @@ get_no_error_domain (enum built_in_funct
     case BUILT_IN_EXPM1:
     case BUILT_IN_EXPL:
     case BUILT_IN_EXPM1L:
+    case BUILT_IN_EXPF64:
+    case BUILT_IN_EXPM1F64:
       /* exp: (-inf, 709)  */
       return get_domain (-1, false, false,
                          709, true, false);
+    case BUILT_IN_EXPF128:
+    case BUILT_IN_EXPM1F128:
+      /* expf128: (-inf, 11356)  */
+      return get_domain (-1, false, false,
+			 11356, true, false);
+    case BUILT_IN_EXP2F16:
+      /* exp2f16: (-inf, 16)  */
+      return get_domain (-1, false, false,
+			 16, true, false);
     case BUILT_IN_EXP2F:
+    case BUILT_IN_EXP2F32:
       /* exp2f: (-inf, 128)  */
       return get_domain (-1, false, false,
                          128, true, false);
     case BUILT_IN_EXP2:
     case BUILT_IN_EXP2L:
+    case BUILT_IN_EXP2F64:
       /* exp2: (-inf, 1024)  */
       return get_domain (-1, false, false,
                          1024, true, false);
+    case BUILT_IN_EXP2F128:
+      /* exp2f128: (-inf, 16384)  */
+      return get_domain (-1, false, false,
+			 16384, true, false);
     case BUILT_IN_EXP10F:
     case BUILT_IN_POW10F:
       /* exp10f: (-inf, 38)  */
--- gcc/testsuite/gcc.dg/pr107547.c.jj	2022-11-07 15:01:29.836952863 +0100
+++ gcc/testsuite/gcc.dg/pr107547.c	2022-11-07 15:00:22.878866103 +0100
@@ -0,0 +1,40 @@
+/* PR tree-optimization/107547 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int x;
+
+void
+foo (void)
+{
+#define TEST(...) \
+  __builtin_acos##__VA_ARGS__ (x);	\
+  __builtin_asin##__VA_ARGS__ (x);	\
+  __builtin_acosh##__VA_ARGS__ (x);	\
+  __builtin_atanh##__VA_ARGS__ (x);	\
+  __builtin_cosh##__VA_ARGS__ (x);	\
+  __builtin_sinh##__VA_ARGS__ (x);	\
+  __builtin_log##__VA_ARGS__ (x);	\
+  __builtin_log2##__VA_ARGS__ (x);	\
+  __builtin_log10##__VA_ARGS__ (x);	\
+  __builtin_log1p##__VA_ARGS__ (x);	\
+  __builtin_exp##__VA_ARGS__ (x);	\
+  __builtin_expm1##__VA_ARGS__ (x);	\
+  __builtin_exp2##__VA_ARGS__ (x);	\
+  __builtin_sqrt##__VA_ARGS__ (x)
+  TEST (f);
+  TEST ();
+  TEST (l);
+#ifdef __FLT16_MAX__
+  TEST (f16);
+#endif
+#ifdef __FLT32_MAX__
+  TEST (f32);
+#endif
+#ifdef __FLT64_MAX__
+  TEST (f64);
+#endif
+#ifdef __FLT128_MAX__
+  TEST (f128);
+#endif
+}

	Jakub


             reply	other threads:[~2022-11-08 11:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08 11:01 Jakub Jelinek [this message]
2022-11-08 12:21 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2o3IekL8TZKHdlR@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=joseph@codesourcery.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).