tree-ssa-threadedge.c (simplify_control_stmt_condition): Look deeper into the SSA_NAM...
authorJeff Law <law@redhat.com>
Mon, 30 Jun 2014 14:08:50 +0000 (08:08 -0600)
committerJeff Law <law@gcc.gnu.org>
Mon, 30 Jun 2014 14:08:50 +0000 (08:08 -0600)
tree-optimization/61607
* tree-ssa-threadedge.c (simplify_control_stmt_condition): Look
deeper into the SSA_NAME_VALUE chain.

tree-optimization/61607
* gcc.dg/tree-ssa/pr61607.c: New test.

From-SVN: r212149

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr61607.c [new file with mode: 0644]
gcc/tree-ssa-threadedge.c

index 70f80885dcdf67ce5e11b9589933d6a9e0bdcc0a..61df10df8d6debd69d9a6c0c2000ed4bb74b633b 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-30  Jeff Law  <law@redhat.com>
+
+       PR tree-optimization/61607
+       * tree-ssa-threadedge.c (simplify_control_stmt_condition): Look
+       deeper into the SSA_NAME_VALUE chain.
+
 2014-06-30  Marek Polacek  <polacek@redhat.com>
 
        * convert.c (convert_to_integer): Don't instrument conversions if the
index 4191a9728cf6e4de10705d7ae73e808796ecb586..4c4b683aec9d3c14469969a0248f59624ace459b 100644 (file)
@@ -1,3 +1,8 @@
+2014-06-30  Jeff Law  <law@redhat.com>
+
+       PR tree-optimization/61607
+       * gcc.dg/tree-ssa/pr61607.c: New test.
+
 2014-06-30  Marek Polacek  <polacek@redhat.com>
 
        * c-c++-common/ubsan/attrib-2.c: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr61607.c b/gcc/testsuite/gcc.dg/tree-ssa/pr61607.c
new file mode 100644 (file)
index 0000000..924d686
--- /dev/null
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -fno-tree-fre -fdump-tree-dom1" } */
+
+void foo(int *);
+void f2(int dst[3], int R)
+{
+  int i, inter[2];
+  _Bool inter0p = 0;
+  _Bool inter1p = 0;
+  for (i = 1; i < R; i++)
+    {
+      inter0p = 1;
+      inter1p = 1;
+    }
+  if (inter0p)
+    inter[0] = 1;
+  if (inter1p)
+    inter[1] = 1;
+  foo(inter);
+}
+
+
+/* There should be precisely two conditionals.  One for the loop condition
+   and one for the test after the loop.  Previously we failed to eliminate
+   the second conditional after the loop.  */
+/* { dg-final { scan-tree-dump-times "if" 2 "dom1"} } */
+
+/* { dg-final { cleanup-tree-dump "dom1" } } */
+
index a76a7ce658750b124715a1c452a417433f9f12af..9807b421c74e80cae5963786214fa166d0fe8009 100644 (file)
@@ -542,16 +542,26 @@ simplify_control_stmt_condition (edge e,
       /* Get the current value of both operands.  */
       if (TREE_CODE (op0) == SSA_NAME)
        {
-          tree tmp = SSA_NAME_VALUE (op0);
-         if (tmp)
-           op0 = tmp;
+         for (int i = 0; i < 2; i++)
+           {
+             if (TREE_CODE (op0) == SSA_NAME
+                 && SSA_NAME_VALUE (op0))
+               op0 = SSA_NAME_VALUE (op0);
+             else
+               break;
+           }
        }
 
       if (TREE_CODE (op1) == SSA_NAME)
        {
-         tree tmp = SSA_NAME_VALUE (op1);
-         if (tmp)
-           op1 = tmp;
+         for (int i = 0; i < 2; i++)
+           {
+             if (TREE_CODE (op1) == SSA_NAME
+                 && SSA_NAME_VALUE (op1))
+               op1 = SSA_NAME_VALUE (op1);
+             else
+               break;
+           }
        }
 
       if (handle_dominating_asserts)
@@ -625,10 +635,17 @@ simplify_control_stmt_condition (edge e,
         It is possible to get loops in the SSA_NAME_VALUE chains
         (consider threading the backedge of a loop where we have
         a loop invariant SSA_NAME used in the condition.  */
-      if (cached_lhs
-         && TREE_CODE (cached_lhs) == SSA_NAME
-         && SSA_NAME_VALUE (cached_lhs))
-       cached_lhs = SSA_NAME_VALUE (cached_lhs);
+      if (cached_lhs)
+       {
+         for (int i = 0; i < 2; i++)
+           {
+             if (TREE_CODE (cached_lhs) == SSA_NAME
+                 && SSA_NAME_VALUE (cached_lhs))
+               cached_lhs = SSA_NAME_VALUE (cached_lhs);
+             else
+               break;
+           }
+       }
 
       /* If we're dominated by a suitable ASSERT_EXPR, then
         update CACHED_LHS appropriately.  */