]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/43655 (-ftree-ter causes FAIL: g++.old-deja/g+...
authorJakub Jelinek <jakub@redhat.com>
Sun, 16 Jan 2011 20:21:42 +0000 (21:21 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sun, 16 Jan 2011 20:21:42 +0000 (21:21 +0100)
Backport from mainline
2010-12-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/43655
* tree-ssa-ter.c (is_replaceable_p): Don't use
gimple_references_memory_p for -O0, instead check for load
by looking at rhs.

* g++.dg/opt/pr43655.C: New test.

From-SVN: r168866

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr43655.C [new file with mode: 0644]
gcc/tree-ssa-ter.c

index d65bebc2019853b7e18bc22deac946f9bae944a9..db6b41f7575788a116d89cdc472f9f001400f943 100644 (file)
@@ -3,6 +3,11 @@
        Backport from mainline
        2010-12-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/43655
+       * tree-ssa-ter.c (is_replaceable_p): Don't use
+       gimple_references_memory_p for -O0, instead check for load
+       by looking at rhs.
+
        PR debug/46893
        * cfgexpand.c (expand_debug_expr): If GET_MODE (op0) is VOIDmode,
        use TYPE_MODE (TREE_TYPE (tem)) instead of mode1.
index fd8d27dc2a47f853c47b55b424a3678c40a8e861..b83af10d258a9166b2edf4c70be4b57d6ce4cac9 100644 (file)
@@ -3,6 +3,9 @@
        Backport from mainline
        2010-12-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/43655
+       * g++.dg/opt/pr43655.C: New test.
+
        PR debug/46893
        * gcc.dg/pr46893.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/opt/pr43655.C b/gcc/testsuite/g++.dg/opt/pr43655.C
new file mode 100644 (file)
index 0000000..f7e370b
--- /dev/null
@@ -0,0 +1,34 @@
+// PR tree-optimization/43655
+// { dg-do run }
+// { dg-options "-O0 -ftree-ter" }
+
+extern "C" void abort ();
+
+struct C
+{
+  C (int i) : val(i) { }
+  C (const C& c) : val(c.val) { }
+  ~C (void) { val = 999; }
+  C& operator = (const C& c) { val = c.val; return *this; }
+  C& inc (int i) { val += i; return *this; }
+  int val;
+};
+
+C
+f ()
+{
+  return C (3);
+}
+
+C
+f (int i)
+{
+  return f ().inc (i);
+}
+
+int
+main ()
+{
+  if (f (2).val != 5)
+    abort ();
+}
index 902b1f07f362ac6aa39def9aa53d9660833caeb2..8c25748a94bbab654af07eed7a21808b99fd3df3 100644 (file)
@@ -416,7 +416,9 @@ is_replaceable_p (gimple stmt)
     return false;
 
   /* Without alias info we can't move around loads.  */
-  if (gimple_references_memory_p (stmt) && !optimize)
+  if (!optimize
+      && gimple_assign_single_p (stmt)
+      && !is_gimple_val (gimple_assign_rhs1 (stmt)))
     return false;
 
   /* Float expressions must go through memory if float-store is on.  */