re PR tree-optimization/57303 (struct miscompiled at -O1 and above)
authorRichard Biener <rguenther@suse.de>
Tue, 21 May 2013 08:11:23 +0000 (08:11 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 21 May 2013 08:11:23 +0000 (08:11 +0000)
2013-05-21  Richard Biener  <rguenther@suse.de>

PR tree-optimization/57303
* tree-ssa-sink.c (statement_sink_location): Improve killing
stmt detection and properly handle self-assignments.

* gcc.dg/torture/pr57303.c: New testcase.

From-SVN: r199135

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr57303.c [new file with mode: 0644]
gcc/tree-ssa-sink.c

index d6113341ba7afb0132768ecaea29289073b70598..0a7c1e701c3d52102de00cacbd4ebb424464252b 100644 (file)
@@ -1,3 +1,9 @@
+2013-05-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/57303
+       * tree-ssa-sink.c (statement_sink_location): Improve killing
+       stmt detection and properly handle self-assignments.
+
 2013-05-21  Christian Bruel  <christian.bruel@st.com>
 
         * dwarf2out.c (multiple_reg_loc_descriptor): Use dbx_reg_number for
index f78e672b66b597f7f3ebc14a7d065d868e64595e..0783914af15fbf8c37ad5847240ffab9f7dda9ec 100644 (file)
@@ -1,3 +1,8 @@
+2013-05-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/57303
+       * gcc.dg/torture/pr57303.c: New testcase.
+
 2013-05-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/57321
diff --git a/gcc/testsuite/gcc.dg/torture/pr57303.c b/gcc/testsuite/gcc.dg/torture/pr57303.c
new file mode 100644 (file)
index 0000000..1ddb5a8
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do run } */
+
+void abort (void);
+
+struct S0
+{
+  int f0;
+};
+struct S1
+{
+  struct S0 f0;
+};
+
+struct S1 x = { {0} };
+struct S1 y = { {1} };
+
+static void
+foo (struct S0 p)
+{
+  struct S0 *l = &y.f0;
+  *l = x.f0;
+  if (p.f0)
+    *l = *l;
+}
+
+int
+main ()
+{
+  foo(y.f0);
+  if (y.f0.f0 != 0)
+    abort ();
+  return 0;
+}
index 0d9029bc66e9686c1a212b6fda24b3f264352df9..87a0a599110e0c0de795ec7aec0901fd42a48f49 100644 (file)
@@ -331,11 +331,19 @@ statement_sink_location (gimple stmt, basic_block frombb,
          gimple use_stmt = USE_STMT (use_p);
 
          /* A killing definition is not a use.  */
-         if (gimple_assign_single_p (use_stmt)
-             && gimple_vdef (use_stmt)
-             && operand_equal_p (gimple_assign_lhs (stmt),
-                                 gimple_assign_lhs (use_stmt), 0))
-           continue;
+         if ((gimple_has_lhs (use_stmt)
+              && operand_equal_p (gimple_assign_lhs (stmt),
+                                  gimple_get_lhs (use_stmt), 0))
+             || stmt_kills_ref_p (use_stmt, gimple_assign_lhs (stmt)))
+           {
+             /* If use_stmt is or might be a nop assignment then USE_STMT
+                acts as a use as well as definition.  */
+             if (stmt != use_stmt
+                 && ref_maybe_used_by_stmt_p (use_stmt,
+                                              gimple_assign_lhs (stmt)))
+               return false;
+             continue;
+           }
 
          if (gimple_code (use_stmt) != GIMPLE_PHI)
            return false;