diff options
author | Richard Guenther <rguenther@suse.de> | 2009-09-22 08:34:52 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2009-09-22 08:34:52 +0000 |
commit | f61e18ec67d800e358448907260604809f3151b9 (patch) | |
tree | 2dae69d5e6d8f6e3ea0f1c4712a4f2998ae5d083 | |
parent | ff7ffb8f2a4670297b53f38c0a751defc59bb47f (diff) | |
download | gcc-f61e18ec67d800e358448907260604809f3151b9.zip gcc-f61e18ec67d800e358448907260604809f3151b9.tar.gz gcc-f61e18ec67d800e358448907260604809f3151b9.tar.bz2 |
re PR tree-optimization/41428 (CCP doesn't fold all comparisons it could)
2009-09-22 Richard Guenther <rguenther@suse.de>
PR tree-optimization/41428
* tree-ssa-ccp.c (ccp_fold_stmt): New function.
(ccp_finalize): Pass it to substitute_and_fold.
* g++.dg/tree-ssa/pr41428.C: New testcase.
From-SVN: r151969
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/tree-ssa/pr41428.C | 15 | ||||
-rw-r--r-- | gcc/tree-ssa-ccp.c | 31 |
4 files changed, 56 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 97dd74b..fa41a8a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2009-09-22 Richard Guenther <rguenther@suse.de> + PR tree-optimization/41428 + * tree-ssa-ccp.c (ccp_fold_stmt): New function. + (ccp_finalize): Pass it to substitute_and_fold. + +2009-09-22 Richard Guenther <rguenther@suse.de> + * tree-ssa-propagate.h (ssa_prop_fold_stmt_fn): Declare. (substitute_and_fold): Adjust prototype. * tree-vrp.c (vrp_evaluate_conditional): Make static. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 588c747..97b6262 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-09-22 Richard Guenther <rguenther@suse.de> + + PR tree-optimization/41428 + * g++.dg/tree-ssa/pr41428.C: New testcase. + 2009-09-22 Jakub Jelinek <jakub@redhat.com> PR middle-end/41429 diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr41428.C b/gcc/testsuite/g++.dg/tree-ssa/pr41428.C new file mode 100644 index 0000000..32716ca --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr41428.C @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-ccp1-details" } */ + +extern "C" void abort (void); +inline void *operator new (__SIZE_TYPE__, void *__p) throw () { return __p; } + +int foo(void) +{ + float f = 0; + int *i = new (&f) int (1); + return *(int *)&f; +} + +/* { dg-final { scan-tree-dump "Folded into: if \\\(1 != 0\\\)" "ccp1" } } */ +/* { dg-final { cleanup-tree-dump "ccp1" } } */ diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 5e30588..4542403 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -229,6 +229,7 @@ typedef enum static prop_value_t *const_val; static void canonicalize_float_value (prop_value_t *); +static bool ccp_fold_stmt (gimple_stmt_iterator *); /* Dump constant propagation value VAL to file OUTF prefixed by PREFIX. */ @@ -724,7 +725,7 @@ ccp_finalize (void) do_dbg_cnt (); /* Perform substitutions based on the known constant values. */ - something_changed = substitute_and_fold (const_val, NULL); + something_changed = substitute_and_fold (const_val, ccp_fold_stmt); free (const_val); const_val = NULL; @@ -1472,6 +1473,34 @@ evaluate_stmt (gimple stmt) return val; } +/* Fold the stmt at *GSI with CCP specific information that propagating + and regular folding does not catch. */ + +static bool +ccp_fold_stmt (gimple_stmt_iterator *gsi) +{ + gimple stmt = gsi_stmt (*gsi); + prop_value_t val; + + if (gimple_code (stmt) != GIMPLE_COND) + return false; + + /* Statement evaluation will handle type mismatches in constants + more gracefully than the final propagation. This allows us to + fold more conditionals here. */ + val = evaluate_stmt (stmt); + if (val.lattice_val != CONSTANT + || TREE_CODE (val.value) != INTEGER_CST) + return false; + + if (integer_zerop (val.value)) + gimple_cond_make_false (stmt); + else + gimple_cond_make_true (stmt); + + return true; +} + /* Visit the assignment statement STMT. Set the value of its LHS to the value computed by the RHS and store LHS in *OUTPUT_P. If STMT creates virtual definitions, set the value of each new name to that |