diff options
author | Richard Guenther <rguenther@suse.de> | 2006-10-21 13:23:41 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2006-10-21 13:23:41 +0000 |
commit | 0778d4e84ac1d0f4dadec932144198770a9b0318 (patch) | |
tree | dd713067369d88527a6fd65d832fd499d903a4c9 | |
parent | 8a1eca08037f5a936526485f1056385708dc5c7c (diff) | |
download | gcc-0778d4e84ac1d0f4dadec932144198770a9b0318.zip gcc-0778d4e84ac1d0f4dadec932144198770a9b0318.tar.gz gcc-0778d4e84ac1d0f4dadec932144198770a9b0318.tar.bz2 |
re PR tree-optimization/3511 (Inlined strlen() could be smarter)
2006-10-21 Richard Guenther <rguenther@suse.de>
PR tree-optimization/3511
* tree-ssa-pre.c (phi_translate): Fold CALL_EXPRs that
got new invariant arguments during PHI translation.
* gcc.dg/tree-ssa/ssa-pre-15.c: New testcase.
From-SVN: r117932
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-15.c | 16 | ||||
-rw-r--r-- | gcc/tree-ssa-pre.c | 17 |
4 files changed, 44 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fdaa244..eb1c329 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2006-10-21 Richard Guenther <rguenther@suse.de> + PR tree-optimization/3511 + * tree-ssa-pre.c (phi_translate): Fold CALL_EXPRs that + got new invariant arguments during PHI translation. + +2006-10-21 Richard Guenther <rguenther@suse.de> + PR middle-end/26898 * fold-const.c (fold_comparison): Fold signed comparisons of the form X +- C1 CMP Y +- C2. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 55d336c..c30830d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2006-10-21 Richard Guenther <rguenther@suse.de> + PR tree-optimization/3511 + * gcc.dg/tree-ssa/ssa-pre-15.c: New testcase. + +2006-10-21 Richard Guenther <rguenther@suse.de> + PR middle-end/26898 * gcc.dg/torture/pr26898-1.c: New testcase. * gcc.dg/torture/pr26898-2.c: Likewise. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-15.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-15.c new file mode 100644 index 0000000..518fda85 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-15.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* Verify we PRE the strlen call, as strlen("") folds to zero. */ + +extern __SIZE_TYPE__ strlen (const char *); + +__SIZE_TYPE__ mystrlen (const char *s) +{ + if (!s) + s = ""; + return strlen(s); +} + +/* { dg-final { scan-tree-dump "= 0;" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index 9c7b89f..ba32b3c 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -1076,6 +1076,7 @@ phi_translate (tree expr, value_set_t set, basic_block pred, tree newexpr; tree vh = get_value_handle (expr); bool listchanged = false; + bool invariantarg = false; VEC (tree, gc) *vuses = VALUE_HANDLE_VUSES (vh); VEC (tree, gc) *tvuses; @@ -1134,10 +1135,26 @@ phi_translate (tree expr, value_set_t set, basic_block pred, if (newval != oldval) { listchanged = true; + invariantarg |= is_gimple_min_invariant (newval); TREE_VALUE (newwalker) = get_value_handle (newval); } } } + + /* In case of new invariant args we might try to fold the call + again. */ + if (invariantarg) + { + tree tmp = fold_ternary (CALL_EXPR, TREE_TYPE (expr), + newop0, newarglist, newop2); + if (tmp) + { + STRIP_TYPE_NOPS (tmp); + if (is_gimple_min_invariant (tmp)) + return tmp; + } + } + if (listchanged) vn_lookup_or_add (newarglist, NULL); |