diff options
author | Richard Biener <rguenther@suse.de> | 2014-05-16 07:57:46 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2014-05-16 07:57:46 +0000 |
commit | a27c386001166cec7abc12d54e96413022bcc747 (patch) | |
tree | 776df230e0884755b1a09582eb5f930870d60be9 /gcc | |
parent | d8c55b91aefb9d6d64cd0ebf2fe5e9a22b1cd71b (diff) | |
download | gcc-a27c386001166cec7abc12d54e96413022bcc747.zip gcc-a27c386001166cec7abc12d54e96413022bcc747.tar.gz gcc-a27c386001166cec7abc12d54e96413022bcc747.tar.bz2 |
tree-ssa-sccvn.c (visit_use): Also constant-fold calls.
2014-05-16 Richard Biener <rguenther@suse.de>
* tree-ssa-sccvn.c (visit_use): Also constant-fold calls.
* gcc.dg/tree-ssa/ssa-fre-41.c: New testcase.
From-SVN: r210491
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-41.c | 12 | ||||
-rw-r--r-- | gcc/tree-ssa-sccvn.c | 72 |
4 files changed, 77 insertions, 15 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5a29ded..3df0bb4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2014-05-16 Richard Biener <rguenther@suse.de> + + * tree-ssa-sccvn.c (visit_use): Also constant-fold calls. + 2014-05-15 Peter Bergner <bergner@vnet.ibm.com> PR target/61193 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 96b6303..8c52f8c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-05-16 Richard Biener <rguenther@suse.de> + + * gcc.dg/tree-ssa/ssa-fre-41.c: New testcase. + 2014-05-15 Martin Jambor <mjambor@suse.cz> PR ipa/61085 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-41.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-41.c new file mode 100644 index 0000000..82ca746 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-41.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-fre1" } */ + +int x; +int foo (void) +{ + x = 1; + return __builtin_ffs (x); +} + +/* { dg-final { scan-tree-dump-not "ffs" "fre1" } } */ +/* { dg-final { cleanup-tree-dump "fre1" } } */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 07b9bd2..93a7e30 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -3566,28 +3566,70 @@ visit_use (tree use) else if (is_gimple_call (stmt)) { tree lhs = gimple_call_lhs (stmt); - - /* ??? We could try to simplify calls. */ - if (lhs && TREE_CODE (lhs) == SSA_NAME) { - if (stmt_has_constants (stmt)) - VN_INFO (lhs)->has_constants = true; - else + /* Try constant folding based on our current lattice. */ + tree simplified = gimple_fold_stmt_to_constant_1 (stmt, + vn_valueize); + if (simplified) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "call "); + print_gimple_expr (dump_file, stmt, 0, 0); + fprintf (dump_file, " simplified to "); + print_generic_expr (dump_file, simplified, 0); + if (TREE_CODE (lhs) == SSA_NAME) + fprintf (dump_file, " has constants %d\n", + expr_has_constants (simplified)); + else + fprintf (dump_file, "\n"); + } + } + /* Setting value numbers to constants will occasionally + screw up phi congruence because constants are not + uniquely associated with a single ssa name that can be + looked up. */ + if (simplified + && is_gimple_min_invariant (simplified)) { - /* We reset expr and constantness here because we may - have been value numbering optimistically, and - iterating. They may become non-constant in this case, - even if they were optimistically constant. */ - VN_INFO (lhs)->has_constants = false; - VN_INFO (lhs)->expr = NULL_TREE; + VN_INFO (lhs)->expr = simplified; + VN_INFO (lhs)->has_constants = true; + changed = set_ssa_val_to (lhs, simplified); + if (gimple_vdef (stmt)) + changed |= set_ssa_val_to (gimple_vdef (stmt), + gimple_vuse (stmt)); + goto done; } - - if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs)) + else if (simplified + && TREE_CODE (simplified) == SSA_NAME) { - changed = defs_to_varying (stmt); + changed = visit_copy (lhs, simplified); + if (gimple_vdef (stmt)) + changed |= set_ssa_val_to (gimple_vdef (stmt), + gimple_vuse (stmt)); goto done; } + else + { + if (stmt_has_constants (stmt)) + VN_INFO (lhs)->has_constants = true; + else + { + /* We reset expr and constantness here because we may + have been value numbering optimistically, and + iterating. They may become non-constant in this case, + even if they were optimistically constant. */ + VN_INFO (lhs)->has_constants = false; + VN_INFO (lhs)->expr = NULL_TREE; + } + + if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs)) + { + changed = defs_to_varying (stmt); + goto done; + } + } } if (!gimple_call_internal_p (stmt) |