aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/20071011-1.c19
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c18
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-9.c2
-rw-r--r--gcc/tree-ssa-forwprop.c32
6 files changed, 76 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 28590a6c41b..9abace31683 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-12 Richard Guenther <rguenther@suse.de>
+
+ PR middle-end/26198
+ * tree-ssa-forwprop.c (can_propagate_from): Do not propagate from
+ a rhs with side-effects or which is a load.
+ (forward_propagate_into_cond): Also try combining both operands.
+
2007-10-12 Uros Bizjak <ubizjak@gmail.com>
PR tree-optimization/33742
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cacf0a9ed7d..97d93ea5ef1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-12 Richard Guenther <rguenther@suse.de>
+
+ PR middle-end/26198
+ * gcc.dg/tree-ssa/forwprop-3.c: New testcase.
+ * gcc.c-torture/execute/20071011-1.c: Likewise.
+ * gcc.dg/tree-ssa/ssa-pre-9.c: Adjust.
+
2007-10-12 Uros Bizjak <ubizjak@gmail.com>
PR tree-optimization/33742
diff --git a/gcc/testsuite/gcc.c-torture/execute/20071011-1.c b/gcc/testsuite/gcc.c-torture/execute/20071011-1.c
new file mode 100644
index 00000000000..631658540b3
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20071011-1.c
@@ -0,0 +1,19 @@
+extern void abort(void);
+void foo(int *p)
+{
+ int x;
+ int y;
+ x = *p;
+ *p = 0;
+ y = *p;
+ if (x != y)
+ return;
+ abort ();
+}
+
+int main()
+{
+ int a = 1;
+ foo(&a);
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c
new file mode 100644
index 00000000000..0d26b8d9cf3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+struct bar {
+ int a[2];
+};
+
+int foo(struct bar *x)
+{
+ int *p = &x->a[0];
+ int *q = &x->a[1];
+ if (p < q)
+ return 1;
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump "Replaced .p_. < q_.. with .1." "forwprop1" } } */
+/* { dg-final { cleanup-tree-dump "forwprop1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-9.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-9.c
index 32e37b99703..30d968b7c53 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-9.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-9.c
@@ -9,5 +9,5 @@ foo (unsigned long a)
return 1;
return 0;
}
-/* { dg-final { scan-tree-dump-times "Eliminated: 1" 1 "fre"} } */
+/* { dg-final { scan-tree-dump-times "return 0;" 0 "fre"} } */
/* { dg-final { cleanup-tree-dump "fre" } } */
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index 3b72b6c44af..b92a9f13f48 100644
--- a/gcc/tree-ssa-forwprop.c
+++ b/gcc/tree-ssa-forwprop.c
@@ -237,6 +237,14 @@ can_propagate_from (tree def_stmt)
{
tree rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
+ /* If the rhs has side-effects we cannot propagate from it. */
+ if (TREE_SIDE_EFFECTS (rhs))
+ return false;
+
+ /* If the rhs is a load we cannot propagate from it. */
+ if (REFERENCE_CLASS_P (rhs))
+ return false;
+
/* We cannot propagate ssa names that occur in abnormal phi nodes. */
switch (TREE_CODE_LENGTH (TREE_CODE (rhs)))
{
@@ -351,7 +359,7 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
do {
tree tmp = NULL_TREE;
tree cond = COND_EXPR_COND (cond_expr);
- tree name, def_stmt, rhs;
+ tree name, def_stmt, rhs0 = NULL_TREE, rhs1 = NULL_TREE;
bool single_use_p;
/* We can do tree combining on SSA_NAME and comparison expressions. */
@@ -366,9 +374,9 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
&& can_propagate_from (def_stmt))
{
tree op1 = TREE_OPERAND (cond, 1);
- rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
+ rhs0 = GIMPLE_STMT_OPERAND (def_stmt, 1);
tmp = combine_cond_expr_cond (TREE_CODE (cond), boolean_type_node,
- fold_convert (TREE_TYPE (op1), rhs),
+ fold_convert (TREE_TYPE (op1), rhs0),
op1, !single_use_p);
}
/* If that wasn't successful, try the second operand. */
@@ -382,12 +390,20 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
|| !can_propagate_from (def_stmt))
return did_something;
- rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
+ rhs1 = GIMPLE_STMT_OPERAND (def_stmt, 1);
tmp = combine_cond_expr_cond (TREE_CODE (cond), boolean_type_node,
op0,
- fold_convert (TREE_TYPE (op0), rhs),
+ fold_convert (TREE_TYPE (op0), rhs1),
!single_use_p);
}
+ /* If that wasn't successful either, try both operands. */
+ if (tmp == NULL_TREE
+ && rhs0 != NULL_TREE
+ && rhs1 != NULL_TREE)
+ tmp = combine_cond_expr_cond (TREE_CODE (cond), boolean_type_node,
+ rhs0,
+ fold_convert (TREE_TYPE (rhs0), rhs1),
+ !single_use_p);
}
else if (TREE_CODE (cond) == SSA_NAME)
{
@@ -397,9 +413,9 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
|| !can_propagate_from (def_stmt))
return did_something;
- rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
- tmp = combine_cond_expr_cond (NE_EXPR, boolean_type_node, rhs,
- build_int_cst (TREE_TYPE (rhs), 0),
+ rhs0 = GIMPLE_STMT_OPERAND (def_stmt, 1);
+ tmp = combine_cond_expr_cond (NE_EXPR, boolean_type_node, rhs0,
+ build_int_cst (TREE_TYPE (rhs0), 0),
false);
}