PR tree-optimization/68021
authoramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 10 Feb 2016 14:09:05 +0000 (14:09 +0000)
committeramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 10 Feb 2016 14:09:05 +0000 (14:09 +0000)
* tree-ssa-loop-ivopts.c (get_computation_aff): Set ratio to 1 if
when computing the value of biv cand by itself.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233269 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 742d555..092797c 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2016-02-10  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * config/aarch64/aarch64.c (cortexa53_tunings): Enable AES fusion.
index a6d388c..2c8be05 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-10  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/68021
+       * gcc.dg/tree-ssa/pr68021.c: New test.
+
 2016-02-10  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/69726
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 4026d28..5302edf 100644 (file)
@@ -3741,7 +3741,19 @@ 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 (use->iv->ssa_name == cand->var_after);
+      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