]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/88074 (g++ hangs on math expression)
authorJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 12:07:12 +0000 (14:07 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 12:07:12 +0000 (14:07 +0200)
Backported from mainline
2019-02-20  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/88074
PR middle-end/89415
* toplev.c (do_compile): Double the emin/emax exponents to workaround
buggy mpc_norm.

2019-02-19  Richard Biener  <rguenther@suse.de>

        PR middle-end/88074
* toplev.c (do_compile): Initialize mpfr's exponent range
based on available float modes.

2019-02-20  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/88074
PR middle-end/89415
* gcc.dg/pr88074-2.c: New test.

2019-02-19  Richard Biener  <rguenther@suse.de>

        PR middle-end/88074
* gcc.dg/pr88074.c: New testcase.

From-SVN: r275116

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr88074-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr88074.c [new file with mode: 0644]
gcc/toplev.c

index 158fa574ee70261b79963a5023109e831ac884bf..58741ccb8b330933308a3073ae1d9de2c4a52702 100644 (file)
@@ -1,6 +1,19 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-02-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/88074
+       PR middle-end/89415
+       * toplev.c (do_compile): Double the emin/emax exponents to workaround
+       buggy mpc_norm.
+
+       2019-02-19  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/88074
+       * toplev.c (do_compile): Initialize mpfr's exponent range
+       based on available float modes.
+
        2019-02-18  Jakub Jelinek  <jakub@redhat.com>
  
        PR target/89361
 2019-05-01  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
 
        Backport from mainline.
-        2019-04-30  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
+       2019-04-30  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
        PR target/86538
        * config/aarch64/aarch64-c.c (aarch64_update_cpp_builtins):
        Define __ARM_FEATURE_ATOMICS
 
 2019-03-21  Bill Schmidt  <wschmidt@linux.ibm.com>
 
-        * config/rs6000/rs6000.c (rs6000_analyze_swaps): Rebuild
-        ud- and du-chains between phases.
+       * config/rs6000/rs6000.c (rs6000_analyze_swaps): Rebuild
+       ud- and du-chains between phases.
 
 2019-03-21  Matthias Klose  <doko@ubuntu.com>
 
index 9270dbcfe5a8a187ca6888830f48890d28ec0c17..d3db33a7fa42e12088ab514bc2cf4272b95d49d4 100644 (file)
@@ -1,3 +1,17 @@
+2019-08-30  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2019-02-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/88074
+       PR middle-end/89415
+       * gcc.dg/pr88074-2.c: New test.
+
+       2019-02-19  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/88074
+       * gcc.dg/pr88074.c: New testcase.
+
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
        Backport fom mainline
        2019-06-21  Jeff Law  <law@redhat.com>
 
-        PR tree-optimization/90949
+       PR tree-optimization/90949
        * gcc.c-torture/execute/pr90949.c: New test.
 
 2019-06-21  Thomas Koenig  <tkoenig@gcc.gnu.org>
diff --git a/gcc/testsuite/gcc.dg/pr88074-2.c b/gcc/testsuite/gcc.dg/pr88074-2.c
new file mode 100644 (file)
index 0000000..a93c19d
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR middle-end/88074 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128 } */
+/* { dg-final { scan-tree-dump-not "link_error " "optimized" } } */
+
+extern void link_error (void);
+int
+main ()
+{
+  if (((__FLT128_MAX__ * 0.5 + __FLT128_MAX__ * 0.5i)
+       / (__FLT128_MAX__ * 0.25 + __FLT128_MAX__ * 0.25i))
+      != (_Complex _Float128) 2)
+    link_error ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/pr88074.c b/gcc/testsuite/gcc.dg/pr88074.c
new file mode 100644 (file)
index 0000000..9f64cc1
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+#include <complex.h>
+
+int main()
+{
+  _Complex double x;
+  __real x = 3.091e+8;
+  __imag x = -4.045e+8;
+  /* This used to spend huge amounts of compile-time inside mpc.  */
+  volatile _Complex double y = ctan (x);
+  return 0;
+}
index f7a753b9cbe926d4c9dd648428af0b8e26014592..6f0bc9fe736f074c2b60f01d0ffaf5a338f3190e 100644 (file)
@@ -1981,6 +1981,36 @@ do_compile ()
        else
          int_n_enabled_p[i] = false;
 
+      /* Initialize mpfrs exponent range.  This is important to get
+         underflow/overflow in a reasonable timeframe.  */
+      machine_mode mode;
+      int min_exp = -1;
+      int max_exp = 1;
+      for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
+          mode != VOIDmode;
+          mode = GET_MODE_WIDER_MODE (mode))
+       if (SCALAR_FLOAT_MODE_P (mode))
+         {
+           const real_format *fmt = REAL_MODE_FORMAT (mode);
+           if (fmt)
+             {
+               /* fmt->emin - fmt->p + 1 should be enough but the
+                  back-and-forth dance in real_to_decimal_for_mode we
+                  do for checking fails due to rounding effects then.  */
+               if ((fmt->emin - fmt->p) < min_exp)
+                 min_exp = fmt->emin - fmt->p;
+               if (fmt->emax > max_exp)
+                 max_exp = fmt->emax;
+             }
+         }
+      /* E.g. mpc_norm assumes it can square a number without bothering with
+        with range scaling, so until that is fixed, double the minimum
+        and maximum exponents, plus add some buffer for arithmetics
+        on the squared numbers.  */
+      if (mpfr_set_emin (2 * (min_exp - 1))
+         || mpfr_set_emax (2 * (max_exp + 1)))
+       sorry ("mpfr not configured to handle all float modes");
+
       /* Set up the back-end if requested.  */
       if (!no_backend)
        backend_init ();