optimize.c (copy_body_r): If MODIFY_EXPR has both arguments identical and they would...
authorJakub Jelinek <jakub@redhat.com>
Sun, 28 Jan 2001 10:35:45 +0000 (11:35 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sun, 28 Jan 2001 10:35:45 +0000 (11:35 +0100)
* 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

gcc/cp/ChangeLog
gcc/cp/optimize.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/inline18.C [new file with mode: 0644]

index 6c2093c67d5026c5f6ed1eefaea27a03adab13ec..3fd306d14ef543d4fba0a3e6656bc4fa8dd15414 100644 (file)
@@ -1,3 +1,9 @@
+2001-01-28  Jakub Jelinek  <jakub@redhat.com>
+
+       * 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  <ghazi@caip.rutgers.edu>
 
        * Make-lang.in: Remove all dependencies on defaults.h.
index 46f1c85761bb0184474f22a6385bd2ef89fa3f09..7a7a27c5b02a4bb8939ade9123e7273509f19831 100644 (file)
@@ -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.  */
index eec04ff1caec9a0d3fecee08df8169c4ee69ce55..edd52229b3ce9e31b5d3bed99ed96c58d9411237 100644 (file)
@@ -1,3 +1,7 @@
+2001-01-28  Jakub Jelinek  <jakub@redhat.com>
+
+       * g++.old-deja/g++.other/inline18.C: New test.
+
 2001-01-27  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * 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 (file)
index 0000000..263fd0e
--- /dev/null
@@ -0,0 +1,13 @@
+// Build don't link:
+// Origin: Jakub Jelinek <jakub@redhat.com>
+// Special g++ Options: -O3
+
+static void foo (int a)
+{
+  a = a;
+}
+
+static void bar (void)
+{
+  foo (-1);
+}