re PR middle-end/82004 (SPEC CPU2017 628.pop2_s miscompare)
authorJakub Jelinek <jakub@redhat.com>
Tue, 20 Feb 2018 13:56:00 +0000 (14:56 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 20 Feb 2018 13:56:00 +0000 (14:56 +0100)
PR middle-end/82004
* match.pd (pow(C,x) -> exp(log(C)*x)): Delay all folding until
after vectorization.

* gfortran.dg/pr82004.f90: New test.

From-SVN: r257846

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr82004.f90 [new file with mode: 0644]

index f890fec..b485a92 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/82004
+       * match.pd (pow(C,x) -> exp(log(C)*x)): Delay all folding until
+       after vectorization.
+
 2018-02-20  Martin Liska  <mliska@suse.cz>
 
        PR driver/83193
index 4452b58..b77f4ea 100644 (file)
@@ -4006,7 +4006,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (simplify
    (pows REAL_CST@0 @1)
    (if (real_compare (GT_EXPR, TREE_REAL_CST_PTR (@0), &dconst0)
-       && real_isfinite (TREE_REAL_CST_PTR (@0)))
+       && real_isfinite (TREE_REAL_CST_PTR (@0))
+       /* As libmvec doesn't have a vectorized exp2, defer optimizing
+          the use_exp2 case until after vectorization.  It seems actually
+          beneficial for all constants to postpone this until later,
+          because exp(log(C)*x), while faster, will have worse precision
+          and if x folds into a constant too, that is unnecessary
+          pessimization.  */
+       && canonicalize_math_after_vectorization_p ())
     (with {
        const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (@0);
        bool use_exp2 = false;
@@ -4021,10 +4028,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      }
      (if (!use_exp2)
       (exps (mult (logs @0) @1))
-      /* As libmvec doesn't have a vectorized exp2, defer optimizing
-        this until after vectorization.  */
-      (if (canonicalize_math_after_vectorization_p ())
-       (exp2s (mult (log2s @0) @1))))))))
+      (exp2s (mult (log2s @0) @1)))))))
 
  (for sqrts (SQRT)
       cbrts (CBRT)
index cfae982..95f06bf 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/82004
+       * gfortran.dg/pr82004.f90: New test.
+
 2018-02-20  Siddhesh Poyarekar  <siddhesh@sourceware.org>
 
        * g++.dg/warn/Wimplicit-fallthrough-3.C: New test case.
diff --git a/gcc/testsuite/gfortran.dg/pr82004.f90 b/gcc/testsuite/gfortran.dg/pr82004.f90
new file mode 100644 (file)
index 0000000..2ddc95f
--- /dev/null
@@ -0,0 +1,18 @@
+! PR middle-end/82004
+! { dg-do run }
+! { dg-options "-Ofast" }
+
+  integer, parameter :: r8 = selected_real_kind(13), i4 = kind(1)
+  integer (i4), parameter :: a = 400, b = 2
+  real (r8), parameter, dimension(b) :: c = (/ .001_r8, 10.00_r8 /)
+  real (r8) :: d, e, f, g, h
+  real (r8), parameter :: j &
+    = 10**(log10(c(1))-(log10(c(b))-log10(c(1)))/real(a))
+
+  d = c(1)
+  e = c(b)
+  f = (log10(e)-log10(d))/real(a)
+  g = log10(d) - f
+  h = 10**(g)
+  if (h.ne.j) stop 1
+end