This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix CCP regression from PR42952
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 4 Feb 2010 17:11:00 +0100 (CET)
- Subject: [PATCH] Fix CCP regression from PR42952
This fixes a CCP regression where an unsuitable formed constatn static
initializer cannot be substituted into all uses. Like with other
cases we now have a pass-specific substitution routine that can
easily handle this.
Bootstrap and regtest running on x86_64-unknown-linux-gnu.
Richard.
2010-02-04 Richard Guenther <rguenther@suse.de>
* tree-ssa-ccp.c (get_symbol_constant_value): Strip all
conversions.
(ccp_fold_stmt): Substitute loads.
* gcc.dg/tree-ssa/ssa-ccp-28.c: New testcase.
Index: gcc/tree-ssa-ccp.c
===================================================================
*** gcc/tree-ssa-ccp.c (revision 156467)
--- gcc/tree-ssa-ccp.c (working copy)
*************** get_symbol_constant_value (tree sym)
*** 283,289 ****
tree val = DECL_INITIAL (sym);
if (val)
{
! STRIP_USELESS_TYPE_CONVERSION (val);
if (is_gimple_min_invariant (val))
{
if (TREE_CODE (val) == ADDR_EXPR)
--- 283,289 ----
tree val = DECL_INITIAL (sym);
if (val)
{
! STRIP_NOPS (val);
if (is_gimple_min_invariant (val))
{
if (TREE_CODE (val) == ADDR_EXPR)
*************** ccp_fold_stmt (gimple_stmt_iterator *gsi
*** 1552,1557 ****
--- 1552,1579 ----
return changed;
}
+ case GIMPLE_ASSIGN:
+ {
+ tree lhs = gimple_assign_lhs (stmt);
+ prop_value_t *val;
+
+ /* If we have a load that turned out to be constant replace it
+ as we cannot propagate into all uses in all cases. */
+ if (gimple_assign_single_p (stmt)
+ && TREE_CODE (lhs) == SSA_NAME
+ && (val = get_value (lhs))
+ && val->lattice_val == CONSTANT)
+ {
+ tree rhs = unshare_expr (val->value);
+ if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
+ rhs = fold_convert (TREE_TYPE (lhs), rhs);
+ gimple_assign_set_rhs_from_tree (gsi, rhs);
+ return true;
+ }
+
+ return false;
+ }
+
default:
return false;
}
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-28.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-28.c (revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-28.c (revision 0)
***************
*** 0 ****
--- 1,26 ----
+ /* { dg-do run } */
+ /* { dg-options "-O -fdump-tree-ccp1" } */
+
+ extern void abort (void);
+
+ static int g[1];
+
+ static int * const p = &g[0];
+ static int * const q = &g[0];
+
+ int main(void)
+ {
+ g[0] = 1;
+ *p = 0;
+ *p = *q;
+ if (g[0] != 0)
+ abort ();
+ return 0;
+ }
+
+ /* We should have replaced all loads from p and q with the constant
+ initial value. */
+
+ /* { dg-final { scan-tree-dump-times "= p;" 0 "ccp1" } } */
+ /* { dg-final { scan-tree-dump-times "= q;" 0 "ccp1" } } */
+ /* { dg-final { cleanup-tree-dump "ccp1" } } */