diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-09-07 18:55:15 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-09-07 18:55:15 +0000 |
commit | e01e695f6b2034ae0c42ace7b632e3828a2bf27c (patch) | |
tree | f2ea2a216c9005e4770e0e608b6d7d4ef7b081f0 | |
parent | b9eb3c64f0a6835d5b4b1f50cf7750c03b4523fe (diff) | |
download | gcc-e01e695f6b2034ae0c42ace7b632e3828a2bf27c.tar.gz |
2007-09-07 Richard Guenther <rguenther@suse.de>
PR tree-optimization/32586
* tree-ssa-sccvn.c (simplify_binary_expression): Avoid
folding if nothing changed.
(simplify_unary_expression): New function. Do tree combining
on conversion like codes.
(try_to_simplify): Call it.
* g++.dg/tree-ssa/pr27090.C: Remove XFAILs.
* gcc.dg/tree-ssa/ssa-fre-1.c: Likewise.
* gcc.dg/tree-ssa/ssa-fre-3.c: Likewise.
* gcc.dg/tree-ssa/ssa-fre-5.c: Likewise.
* gcc.dg/tree-ssa/ssa-fre-4.c: Likewise, remove scan for
now obsolete simplification.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@128251 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/tree-ssa/pr27090.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-1.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-3.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-4.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-5.c | 2 | ||||
-rw-r--r-- | gcc/tree-ssa-sccvn.c | 66 |
8 files changed, 85 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7d2b14ed717..c6e6daa6a83 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2007-09-07 Richard Guenther <rguenther@suse.de> + + Reapply + 2007-09-06 Richard Guenther <rguenther@suse.de> + + PR tree-optimization/32586 + * tree-ssa-sccvn.c (simplify_binary_expression): Avoid + folding if nothing changed. + (simplify_unary_expression): New function. Do tree combining + on conversion like codes. + (try_to_simplify): Call it. + 2007-09-07 John David Anglin <dave.anglin@nrc-cnrc.gc.ca> PR target/33286 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 13ab39940a9..f704b279dd1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2007-09-07 Richard Guenther <rguenther@suse.de> + + Reapply + 2007-09-06 Richard Guenther <rguenther@suse.de> + + PR tree-optimization/32586 + * g++.dg/tree-ssa/pr27090.C: Remove XFAILs. + * gcc.dg/tree-ssa/ssa-fre-1.c: Likewise. + * gcc.dg/tree-ssa/ssa-fre-3.c: Likewise. + * gcc.dg/tree-ssa/ssa-fre-5.c: Likewise. + * gcc.dg/tree-ssa/ssa-fre-4.c: Likewise, remove scan for + now obsolete simplification. + 2007-09-07 Dorit Nuzman <dorit@il.ibm.com> PR tree-optimization/33299 diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr27090.C b/gcc/testsuite/g++.dg/tree-ssa/pr27090.C index 70ef1e09d57..a56357a1b52 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr27090.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr27090.C @@ -17,5 +17,5 @@ int foo(Foo& f) return f.get(); } -/* { dg-final { scan-tree-dump "return f->x;" "optimized" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump "return f->x;" "optimized" } } */ /* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-1.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-1.c index e8c57512bbd..0cb63242c0e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-1.c @@ -11,6 +11,6 @@ int f(int *a) return *c + t; } -/* { dg-final { scan-tree-dump "Replaced \\\(int \\\*\\\) b_.*with a_" "fre" { xfail *-*-* } } } */ -/* { dg-final { scan-tree-dump "Replaced \\\*c_.*with t_" "fre" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump "Replaced \\\(int \\\*\\\) b_.*with a_" "fre" } } */ +/* { dg-final { scan-tree-dump "Replaced \\\*c_.*with t_" "fre" } } */ /* { dg-final { cleanup-tree-dump "fre" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-3.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-3.c index e22064624ae..ebc91e77518 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-3.c @@ -11,5 +11,5 @@ foo (int a, int b) return aa + bb; } -/* { dg-final { scan-tree-dump "Replaced \\\(int\\\) aa_.*with a_" "fre" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump "Replaced \\\(int\\\) aa_.*with a_" "fre" } } */ /* { dg-final { cleanup-tree-dump "fre" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-4.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-4.c index 2b2353f3363..04208a2290d 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-4.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-4.c @@ -9,6 +9,5 @@ char bar(char f) return wrap(f); } -/* { dg-final { scan-tree-dump "Replaced \\\(char\\\) .*with " "fre" { xfail *-*-* } } } */ -/* { dg-final { scan-tree-dump "Replaced \\\(int\\\) .*with " "fre" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump "Replaced \\\(char\\\) .*with " "fre" } } */ /* { dg-final { cleanup-tree-dump "fre" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-5.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-5.c index db6346cc2e7..7ef20c2214d 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-5.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-5.c @@ -10,5 +10,5 @@ bar (unsigned int t) return a == t; } -/* { dg-final { scan-tree-dump "Replaced \\\(unsigned int\\\) a_.*with t_" "fre" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump "Replaced \\\(unsigned int\\\) a_.*with t_" "fre" } } */ /* { dg-final { cleanup-tree-dump "fre" } } */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 855f42af995..bca0e8473ae 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1411,6 +1411,11 @@ simplify_binary_expression (tree rhs) op1 = SSA_VAL (op1); } + /* Avoid folding if nothing changed. */ + if (op0 == TREE_OPERAND (rhs, 0) + && op1 == TREE_OPERAND (rhs, 1)) + return NULL_TREE; + result = fold_binary (TREE_CODE (rhs), TREE_TYPE (rhs), op0, op1); /* Make sure result is not a complex expression consisting @@ -1423,6 +1428,50 @@ simplify_binary_expression (tree rhs) return NULL_TREE; } +/* Simplify the unary expression RHS, and return the result if + simplified. */ + +static tree +simplify_unary_expression (tree rhs) +{ + tree result = NULL_TREE; + tree op0 = TREE_OPERAND (rhs, 0); + + if (TREE_CODE (op0) != SSA_NAME) + return NULL_TREE; + + if (VN_INFO (op0)->has_constants) + op0 = valueize_expr (VN_INFO (op0)->expr); + else if (TREE_CODE (rhs) == NOP_EXPR + || TREE_CODE (rhs) == CONVERT_EXPR + || TREE_CODE (rhs) == REALPART_EXPR + || TREE_CODE (rhs) == IMAGPART_EXPR) + { + /* We want to do tree-combining on conversion-like expressions. + Make sure we feed only SSA_NAMEs or constants to fold though. */ + tree tem = valueize_expr (VN_INFO (op0)->expr); + if (UNARY_CLASS_P (tem) + || BINARY_CLASS_P (tem) + || TREE_CODE (tem) == SSA_NAME + || is_gimple_min_invariant (tem)) + op0 = tem; + } + + /* Avoid folding if nothing changed, but remember the expression. */ + if (op0 == TREE_OPERAND (rhs, 0)) + return rhs; + + result = fold_unary (TREE_CODE (rhs), TREE_TYPE (rhs), op0); + if (result) + { + STRIP_USELESS_TYPE_CONVERSION (result); + if (valid_gimple_expression_p (result)) + return result; + } + + return rhs; +} + /* Try to simplify RHS using equivalences and constant folding. */ static tree @@ -1457,21 +1506,14 @@ try_to_simplify (tree stmt, tree rhs) if (result) return result; } - break; + /* Fallthrough for some codes. */ + if (!(TREE_CODE (rhs) == REALPART_EXPR + || TREE_CODE (rhs) == IMAGPART_EXPR)) + break; /* We could do a little more with unary ops, if they expand into binary ops, but it's debatable whether it is worth it. */ case tcc_unary: - { - tree result = NULL_TREE; - tree op0 = TREE_OPERAND (rhs, 0); - if (TREE_CODE (op0) == SSA_NAME && VN_INFO (op0)->has_constants) - op0 = VN_INFO (op0)->expr; - else if (TREE_CODE (op0) == SSA_NAME && SSA_VAL (op0) != op0) - op0 = SSA_VAL (op0); - result = fold_unary (TREE_CODE (rhs), TREE_TYPE (rhs), op0); - if (result) - return result; - } + return simplify_unary_expression (rhs); break; case tcc_comparison: case tcc_binary: |