re PR tree-optimization/20913 (copy-prop does not fold conditionals)
authorKazu Hirata <kazu@cs.umass.edu>
Wed, 13 Apr 2005 15:28:55 +0000 (15:28 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Wed, 13 Apr 2005 15:28:55 +0000 (15:28 +0000)
gcc/
PR tree-optimization/20913
* tree-ssa-copy.c (copy_prop_visit_cond_stmt): Fold COND_EXPR.

testsuite/
PR tree-optimization/20913
* gcc.dg/tree-ssa/pr20913.c: New.

From-SVN: r98090

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

index 1a5f5f85d9044975a002b87fc88652e4a052493c..3d0636cc6f8fdfa8f8a28fb26167b8414b6bef00 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-13  Kazu Hirata  <kazu@cs.umass.edu>
+
+       PR tree-optimization/20913
+       * tree-ssa-copy.c (copy_prop_visit_cond_stmt): Fold COND_EXPR.
+
 2005-04-13  Julian Brown  <julian@codesourcery.com>
 
        * config/elfos.h (MAKE_DECL_ONE_ONLY): Redefined to stop DECL_WEAK from
index de9f91137cac6e88337c09aeb96a29e6da015990..6faba54bdb00948aa56d4c3b09263e208cf7c035 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-13  Kazu Hirata  <kazu@cs.umass.edu>
+
+       PR tree-optimization/20913
+       * gcc.dg/tree-ssa/pr20913.c: New.
+
 2005-04-13  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/13744
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr20913.c b/gcc/testsuite/gcc.dg/tree-ssa/pr20913.c
new file mode 100644 (file)
index 0000000..da09183
--- /dev/null
@@ -0,0 +1,25 @@
+/* PR tree-optimization/20913
+   COPY-PROP did not fold COND_EXPR, blocking some copy propagation
+   opportunities.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-dominator-opts -fdump-tree-copyprop1-details" } */
+
+int
+foo (int a, int b, int c, int d)
+{
+  int x, y;
+
+  b = a;
+  if (a == b)
+    x = c;
+  else
+    x = d;
+
+  if (x == c)
+    return a;
+  else
+    return b;
+}
+
+/* { dg-final { scan-tree-dump-times "with if \\(1\\)" 2 "copyprop1"} } */
index 91d80a7aef90b9a0cc7fe4b1255a2603257e633b..b9544f8897968ca758514c79d0e3ce9c41ef7e29 100644 (file)
@@ -626,9 +626,16 @@ copy_prop_visit_cond_stmt (tree stmt, edge *taken_edge_p)
          print_generic_stmt (dump_file, cond, 0);
        }
 
-      *taken_edge_p = find_taken_edge (bb_for_stmt (stmt), cond);
-      if (*taken_edge_p)
-       retval = SSA_PROP_INTERESTING;
+      /* We can fold COND only and get a useful result only when we
+        have the same SSA_NAME on both sides of a comparison
+        operator.  */
+      if (TREE_CODE (TREE_OPERAND (cond, 0)) == SSA_NAME
+         && TREE_OPERAND (cond, 0) == TREE_OPERAND (cond, 1))
+       {
+         *taken_edge_p = find_taken_edge (bb_for_stmt (stmt), fold (cond));
+         if (*taken_edge_p)
+           retval = SSA_PROP_INTERESTING;
+       }
 
       /* Restore the original operands.  */
       for (i = 0; i < NUM_USES (uses); i++)