This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR26135, store copyprop being not effective
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 7 Feb 2006 16:44:37 +0100 (CET)
- Subject: [PATCH] Fix PR26135, store copyprop being not effective
This adds the missing parts to the copyprop implementation to do store
copyprop.
Bootstrapped and tested on x86_64-unknown-linux-gnu, plain and with
-fno-tree-dominator-opts (as most store copyprop opportunities are
already handled by DOM).
Ok for mainline?
Thanks,
Richard.
2006-02-07 Richard Guenther <rguenther@suse.de>
* tree-ssa-copy.c (stmt_may_generate_copy): Handle memory
loads for store copy-prop.
(copy_prop_visit_stmt): Likewise.
* gcc.dg/tree-ssa/ssa-copyprop-1.c: New testcase.
Index: tree-ssa-copy.c
===================================================================
*** tree-ssa-copy.c (revision 110646)
--- tree-ssa-copy.c (working copy)
*************** stmt_may_generate_copy (tree stmt)
*** 376,382 ****
/* Otherwise, the only statements that generate useful copies are
assignments whose RHS is just an SSA name that doesn't flow
through abnormal edges. */
! return TREE_CODE (rhs) == SSA_NAME && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs);
}
--- 376,385 ----
/* Otherwise, the only statements that generate useful copies are
assignments whose RHS is just an SSA name that doesn't flow
through abnormal edges. */
! return (do_store_copy_prop
! && TREE_CODE (lhs) == SSA_NAME)
! || (TREE_CODE (rhs) == SSA_NAME
! && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs));
}
*************** copy_prop_visit_stmt (tree stmt, edge *t
*** 692,697 ****
--- 695,728 ----
see if the lattice value of its output has changed. */
retval = copy_prop_visit_assignment (stmt, result_p);
}
+ else if (TREE_CODE (stmt) == MODIFY_EXPR
+ && TREE_CODE (TREE_OPERAND (stmt, 0)) == SSA_NAME
+ && do_store_copy_prop
+ && stmt_makes_single_load (stmt))
+ {
+ /* If the statement is a copy assignment with a memory load
+ on the RHS, see if we know the value of this load and
+ update the lattice accordingly. */
+ prop_value_t *val = get_value_loaded_by (stmt, copy_of);
+ if (val
+ && val->mem_ref
+ && is_gimple_reg (val->value)
+ && operand_equal_p (val->mem_ref, TREE_OPERAND (stmt, 1), 0))
+ {
+ bool changed;
+ changed = set_copy_of_val (TREE_OPERAND (stmt, 0),
+ val->value, val->mem_ref);
+ if (changed)
+ {
+ *result_p = TREE_OPERAND (stmt, 0);
+ retval = SSA_PROP_INTERESTING;
+ }
+ else
+ retval = SSA_PROP_NOT_INTERESTING;
+ }
+ else
+ retval = SSA_PROP_VARYING;
+ }
else if (TREE_CODE (stmt) == COND_EXPR)
{
/* See if we can determine which edge goes out of a conditional
Index: testsuite/gcc.dg/tree-ssa/ssa-copyprop-1.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/ssa-copyprop-1.c (revision 0)
--- testsuite/gcc.dg/tree-ssa/ssa-copyprop-1.c (revision 0)
***************
*** 0 ****
--- 1,12 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fno-tree-dominator-opts -fdump-tree-store_copyprop-details" } */
+
+ typedef struct { int i; int j; } A;
+ int foo(A *a, int i)
+ {
+ a->i = i;
+ return a->i;
+ }
+
+ /* { dg-final { scan-tree-dump "return i" "store_copyprop" } } */
+ /* { dg-final { cleanup-tree-dump "store_copyprop" } } */