re PR tree-optimization/72772 (Missed SCEV after pass reordering@236440)
authorBin Cheng <bin.cheng@arm.com>
Tue, 9 Aug 2016 15:08:02 +0000 (15:08 +0000)
committerBin Cheng <amker@gcc.gnu.org>
Tue, 9 Aug 2016 15:08:02 +0000 (15:08 +0000)
PR tree-optimization/72772
* tree-ssa-loop-niter.c (loop_exits_before_overflow): Check equality
for expanded base.

gcc/testsuite
PR tree-optimization/pr72772
* gcc.dg/tree-ssa/pr72772.c: New test.

From-SVN: r239291

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

index 8fdba0258454235dbfbccaacdc24fe51e2d6c546..ff169b580eaf24dd537b61f15c3bfd0a8b978b03 100644 (file)
@@ -1,3 +1,9 @@
+2016-08-09  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/72772
+       * tree-ssa-loop-niter.c (loop_exits_before_overflow): Check equality
+       for expanded base.
+
 2016-08-09  Bin Cheng  <bin.cheng@arm.com>
 
        PR tree-optimization/72772
index 12a58e8935baa16139c0d7f73f860d68d2a550d1..3a5468cbb478ff90d4dd6f14f947804d9caa6bcd 100644 (file)
@@ -1,3 +1,8 @@
+2016-08-09  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/pr72772
+       * gcc.dg/tree-ssa/pr72772.c: New test.
+
 2016-08-09  Matthew Fortune  <matthew.fortune@imgtec.com>
 
        PR rtl-optimization/66669
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr72772.c b/gcc/testsuite/gcc.dg/tree-ssa/pr72772.c
new file mode 100644 (file)
index 0000000..b998561
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-loop-distribution -fdump-tree-ldist-details" } */
+
+int foo (int flag, char *a)
+{
+  short i, j;
+  short l = 0;
+  if (flag == 1)
+    l = 3;
+
+  for (i = 0; i < 4; i++)
+    {
+      for (j = l - 1; j > 0; j--)
+        a[j] = a[j - 1];
+      a[0] = i;
+    }
+}
+
+/* Addresses of array reference a[j] and a[j - 1] are SCEVs.  */
+/* { dg-final { scan-tree-dump-not "failed: evolution of base is not affine." "ldist" } } */
+
index a34672afd24aea019a25b44805602af20da668d5..a50d2b4b43ee88eececa1fb59ea7758545904351 100644 (file)
@@ -4214,7 +4214,7 @@ loop_exits_before_overflow (tree base, tree step,
       for (civ = loop->control_ivs; civ; civ = civ->next)
        {
          enum tree_code code;
-         tree stepped, extreme, civ_type = TREE_TYPE (civ->step);
+         tree civ_type = TREE_TYPE (civ->step);
 
          /* Have to consider type difference because operand_equal_p ignores
             that for constants.  */
@@ -4227,11 +4227,13 @@ loop_exits_before_overflow (tree base, tree step,
            continue;
 
          /* Done proving if this is a no-overflow control IV.  */
-         if (operand_equal_p (base, civ->base, 0)
-             /* Control IV is recorded after expanding simple operations,
-                Here we compare it against expanded base too.  */
-             || operand_equal_p (expand_simple_operations (base),
-                                 civ->base, 0))
+         if (operand_equal_p (base, civ->base, 0))
+           return true;
+
+         /* Control IV is recorded after expanding simple operations,
+            Here we expand base and compare it too.  */
+         tree expanded_base = expand_simple_operations (base);
+         if (operand_equal_p (expanded_base, civ->base, 0))
            return true;
 
          /* If this is a before stepping control IV, in other words, we have
@@ -4253,9 +4255,14 @@ loop_exits_before_overflow (tree base, tree step,
          else
            code = PLUS_EXPR;
 
-         stepped = fold_build2 (code, TREE_TYPE (base), base, step);
-         if (operand_equal_p (stepped, civ->base, 0))
+         tree stepped = fold_build2 (code, TREE_TYPE (base), base, step);
+         tree expanded_stepped = fold_build2 (code, TREE_TYPE (base),
+                                              expanded_base, step);
+         if (operand_equal_p (stepped, civ->base, 0)
+             || operand_equal_p (expanded_stepped, civ->base, 0))
            {
+             tree extreme;
+
              if (tree_int_cst_sign_bit (step))
                {
                  code = LT_EXPR;