Commit 10372bd4 by Richard Guenther Committed by Richard Biener

re PR middle-end/26198 (Unfolded comparison after cfg_cleanup)

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.

	* 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.

From-SVN: r129256
parent 6d3bf849
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> 2007-10-12 Uros Bizjak <ubizjak@gmail.com>
PR tree-optimization/33742 PR tree-optimization/33742
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> 2007-10-12 Uros Bizjak <ubizjak@gmail.com>
PR tree-optimization/33742 PR tree-optimization/33742
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;
}
/* { 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" } } */
...@@ -9,5 +9,5 @@ foo (unsigned long a) ...@@ -9,5 +9,5 @@ foo (unsigned long a)
return 1; return 1;
return 0; 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" } } */ /* { dg-final { cleanup-tree-dump "fre" } } */
...@@ -237,6 +237,14 @@ can_propagate_from (tree def_stmt) ...@@ -237,6 +237,14 @@ can_propagate_from (tree def_stmt)
{ {
tree rhs = GIMPLE_STMT_OPERAND (def_stmt, 1); 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. */ /* We cannot propagate ssa names that occur in abnormal phi nodes. */
switch (TREE_CODE_LENGTH (TREE_CODE (rhs))) switch (TREE_CODE_LENGTH (TREE_CODE (rhs)))
{ {
...@@ -351,7 +359,7 @@ forward_propagate_into_cond (tree cond_expr, tree stmt) ...@@ -351,7 +359,7 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
do { do {
tree tmp = NULL_TREE; tree tmp = NULL_TREE;
tree cond = COND_EXPR_COND (cond_expr); 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; bool single_use_p;
/* We can do tree combining on SSA_NAME and comparison expressions. */ /* We can do tree combining on SSA_NAME and comparison expressions. */
...@@ -366,9 +374,9 @@ forward_propagate_into_cond (tree cond_expr, tree stmt) ...@@ -366,9 +374,9 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
&& can_propagate_from (def_stmt)) && can_propagate_from (def_stmt))
{ {
tree op1 = TREE_OPERAND (cond, 1); 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, 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); op1, !single_use_p);
} }
/* If that wasn't successful, try the second operand. */ /* If that wasn't successful, try the second operand. */
...@@ -382,12 +390,20 @@ forward_propagate_into_cond (tree cond_expr, tree stmt) ...@@ -382,12 +390,20 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
|| !can_propagate_from (def_stmt)) || !can_propagate_from (def_stmt))
return did_something; 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, tmp = combine_cond_expr_cond (TREE_CODE (cond), boolean_type_node,
op0, op0,
fold_convert (TREE_TYPE (op0), rhs), fold_convert (TREE_TYPE (op0), rhs1),
!single_use_p); !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) else if (TREE_CODE (cond) == SSA_NAME)
{ {
...@@ -397,9 +413,9 @@ forward_propagate_into_cond (tree cond_expr, tree stmt) ...@@ -397,9 +413,9 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
|| !can_propagate_from (def_stmt)) || !can_propagate_from (def_stmt))
return did_something; return did_something;
rhs = GIMPLE_STMT_OPERAND (def_stmt, 1); rhs0 = GIMPLE_STMT_OPERAND (def_stmt, 1);
tmp = combine_cond_expr_cond (NE_EXPR, boolean_type_node, rhs, tmp = combine_cond_expr_cond (NE_EXPR, boolean_type_node, rhs0,
build_int_cst (TREE_TYPE (rhs), 0), build_int_cst (TREE_TYPE (rhs0), 0),
false); false);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment