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
This commit is contained in:
Richard Guenther 2007-10-12 08:42:13 +00:00 committed by Richard Biener
parent 6d3bf8498d
commit 10372bd499
6 changed files with 76 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -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;
}

View file

@ -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" } } */

View file

@ -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" } } */

View file

@ -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);
}