]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/68021 (ice in rewrite_use_nonlinear_expr with -O3)
authorBin Cheng <amker@gcc.gnu.org>
Tue, 11 Apr 2017 08:15:51 +0000 (08:15 +0000)
committerBin Cheng <amker@gcc.gnu.org>
Tue, 11 Apr 2017 08:15:51 +0000 (08:15 +0000)
Backport from mainline
2016-02-10  Bin Cheng  <bin.cheng@arm.com>

PR tree-optimization/68021
* tree-ssa-loop-ivopts.c (get_computation_aff): Set ratio to 1 if
when computing the value of biv cand by itself.

gcc/testsuite
PR tree-optimization/80345
* gcc.c-torture/compile/pr80345.c

Backport from mainline
2016-02-10  Bin Cheng  <bin.cheng@arm.com>

PR tree-optimization/68021
* gcc.dg/tree-ssa/pr68021.c: New test.

From-SVN: r246833

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr80345.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr68021.c [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.c

index 07eb63cc94951787d81e7466a3e6348a862693bc..f5e533a35c4b5d80e5ba1a6f561bd2fae0fabf86 100644 (file)
@@ -1,3 +1,12 @@
+2017-04-11  Bin Cheng  <bin.cheng@arm.com>
+
+       Backport from mainline
+       2016-02-10  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/68021
+       * tree-ssa-loop-ivopts.c (get_computation_aff): Set ratio to 1 if
+       when computing the value of biv cand by itself.
+
 2017-04-08  Andreas Tobler  <andreast@gcc.gnu.org>
 
        Backport from mainline
@@ -9,7 +18,7 @@
 2017-04-07  Andreas Tobler  <andreast@gcc.gnu.org>
 
        Backport from mainline
-        2017-04-07  Andreas Tobler  <andreast@gcc.gnu.org>
+       2017-04-07  Andreas Tobler  <andreast@gcc.gnu.org>
 
        * config/aarch64/aarch64-freebsd.h: Define WCHAR_T.
 
index a097be1849537ef392678fde557840ab2fcad6b1..cab6462d171a74d86eed8c1649e48de4dc8e5d4d 100644 (file)
@@ -1,3 +1,14 @@
+2017-04-11  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/80345
+       * gcc.c-torture/compile/pr80345.c
+
+       Backport from mainline
+       2016-02-10  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/68021
+       * gcc.dg/tree-ssa/pr68021.c: New test.
+
 2017-04-07  Uros Bizjak  <ubizjak@gmail.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr80345.c b/gcc/testsuite/gcc.c-torture/compile/pr80345.c
new file mode 100644 (file)
index 0000000..9762f7c
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR tree-optimization/80345 */
+
+typedef long mp_limb_signed_t;
+void fn1(mp_limb_signed_t p1) {
+  int *a = (int *)1;
+  mp_limb_signed_t i, j;
+  i = 0;
+  for (; i < p1; i++) {
+    j = 0;
+    for (; j <= i; j++)
+      *a++ = 0;
+    j = i + 1;
+    for (; j < p1; j++)
+      a++;
+  }
+}
+void fn2() { fn1((mp_limb_signed_t)fn2); }
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr68021.c b/gcc/testsuite/gcc.dg/tree-ssa/pr68021.c
new file mode 100644 (file)
index 0000000..f60b1ff
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+char a;
+void fn1 (char *p1, int p2, int p3)
+{
+  int i, x;
+  for (i = 0; i < 10; i++)
+    {
+      for (x = 0; x < p3; x++)
+       {
+         *p1 = a;
+         p1--;
+       }
+      p1 += p2;
+    }
+}
index 6c964308067f6a35faa3daa37e10087a09a5c8ab..1d642610cb78db32f20456b2c10f026a92fefa91 100644 (file)
@@ -3118,7 +3118,18 @@ get_computation_aff (struct loop *loop,
       var = fold_convert (uutype, var);
     }
 
-  if (!constant_multiple_of (ustep, cstep, &rat))
+  /* Ratio is 1 when computing the value of biv cand by itself.
+     We can't rely on constant_multiple_of in this case because the
+     use is created after the original biv is selected.  The call
+     could fail because of inconsistent fold behavior.  See PR68021
+     for more information.  */
+  if (cand->pos == IP_ORIGINAL && cand->incremented_at == use->stmt)
+    {
+      gcc_assert (is_gimple_assign (use->stmt));
+      gcc_assert (gimple_assign_lhs (use->stmt) == cand->var_after);
+      rat = 1;
+    }
+  else if (!constant_multiple_of (ustep, cstep, &rat))
     return false;
 
   /* In case both UBASE and CBASE are shortened to UUTYPE from some common