From: Jakub Jelinek Date: Sun, 28 Jan 2001 10:35:45 +0000 (+0100) Subject: optimize.c (copy_body_r): If MODIFY_EXPR has both arguments identical and they would... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6001735ea0da3d5d89a8f249a79fc8198ff28513;p=gcc.git optimize.c (copy_body_r): If MODIFY_EXPR has both arguments identical and they would be replaced with... * optimize.c (copy_body_r): If MODIFY_EXPR has both arguments identical and they would be replaced with constant, remove MODIFY_EXPR from the tree. * g++.old-deja/g++.other/inline18.C: New test. From-SVN: r39317 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6c2093c67d5..3fd306d14ef 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2001-01-28 Jakub Jelinek + + * optimize.c (copy_body_r): If MODIFY_EXPR has both arguments + identical and they would be replaced with constant, remove + MODIFY_EXPR from the tree. + 2001-01-27 Kaveh R. Ghazi * Make-lang.in: Remove all dependencies on defaults.h. diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c index 46f1c85761b..7a7a27c5b02 100644 --- a/gcc/cp/optimize.c +++ b/gcc/cp/optimize.c @@ -338,6 +338,26 @@ copy_body_r (tp, walk_subtrees, data) TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3); TREE_OPERAND (*tp, 3) = NULL_TREE; } + else if (TREE_CODE (*tp) == MODIFY_EXPR + && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1) + && nonstatic_local_decl_p (TREE_OPERAND (*tp, 0)) + && DECL_CONTEXT (TREE_OPERAND (*tp, 0)) == fn) + { + /* Assignments like a = a; don't generate any rtl code + and don't count as variable modification. Avoid + keeping bogosities like 0 = 0. */ + tree decl = TREE_OPERAND (*tp, 0), value; + splay_tree_node n; + + n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl); + if (n) + { + value = (tree) n->value; + STRIP_TYPE_NOPS (value); + if (TREE_CONSTANT (value) || TREE_READONLY_DECL_P (value)) + *tp = value; + } + } } /* Keep iterating. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eec04ff1cae..edd52229b3c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-01-28 Jakub Jelinek + + * g++.old-deja/g++.other/inline18.C: New test. + 2001-01-27 Kaveh R. Ghazi * gcc.c-torture/execute/stdio-opt-2.c: Also test __builtin_puts diff --git a/gcc/testsuite/g++.old-deja/g++.other/inline18.C b/gcc/testsuite/g++.old-deja/g++.other/inline18.C new file mode 100644 index 00000000000..263fd0eb116 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/inline18.C @@ -0,0 +1,13 @@ +// Build don't link: +// Origin: Jakub Jelinek +// Special g++ Options: -O3 + +static void foo (int a) +{ + a = a; +} + +static void bar (void) +{ + foo (-1); +}