summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr20913.c25
-rw-r--r--gcc/tree-ssa-copy.c13
4 files changed, 45 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 1a5f5f85d90..3d0636cc6f8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index de9f91137ca..6faba54bdb0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 00000000000..da09183bee3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr20913.c
@@ -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"} } */
diff --git a/gcc/tree-ssa-copy.c b/gcc/tree-ssa-copy.c
index 91d80a7aef9..b9544f88979 100644
--- a/gcc/tree-ssa-copy.c
+++ b/gcc/tree-ssa-copy.c
@@ -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++)