OSDN Git Service

2014-05-07 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 May 2014 10:01:36 +0000 (10:01 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 May 2014 10:01:36 +0000 (10:01 +0000)
Backport from mainline
2013-11-29  Richard Biener  <rguenther@suse.de>

PR tree-optimization/59334
* tree-ssa-dce.c (eliminate_unnecessary_stmts): Fix bug
in previous commit.

2013-11-28  Richard Biener  <rguenther@suse.de>

PR tree-optimization/59330
* tree-ssa-dce.c (eliminate_unnecessary_stmts): Simplify
and fix delayed marking of free calls not necessary.

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

2014-01-09  Richard Biener  <rguenther@suse.de>

PR tree-optimization/59715
* tree-cfg.h (split_critical_edges): Declare.
* tree-cfg.c (split_critical_edges): Export.
* tree-ssa-sink.c (execute_sink_code): Split critical edges.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@210146 138bc75d-0d04-0410-961f-82ee72b054a4

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

index ed7ce78..156b5a5 100644 (file)
@@ -1,5 +1,27 @@
 2014-05-07  Richard Biener  <rguenther@suse.de>
 
+       Backport from mainline
+       2013-11-29  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59334
+       * tree-ssa-dce.c (eliminate_unnecessary_stmts): Fix bug
+       in previous commit.
+
+       2013-11-28  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59330
+       * tree-ssa-dce.c (eliminate_unnecessary_stmts): Simplify
+       and fix delayed marking of free calls not necessary.
+
+       2014-01-09  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59715
+       * tree-cfg.h (split_critical_edges): Declare.
+       * tree-cfg.c (split_critical_edges): Export.
+       * tree-ssa-sink.c (execute_sink_code): Split critical edges.
+
+2014-05-07  Richard Biener  <rguenther@suse.de>
+
        PR tree-optimization/57864
        * tree-ssa-pre.c (phi_translate_1): Backport NAME case
        simplification from mainline.  Do not lookup the VN
index aeacf94..2bd98d4 100644 (file)
@@ -1,5 +1,18 @@
 2014-05-07  Richard Biener  <rguenther@suse.de>
 
+       Backport from mainline
+       2013-11-28  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59330
+       * gcc.dg/torture/pr59330.c: New testcase.
+
+       2014-01-09  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59715
+       * gcc.dg/torture/pr59715.c: New testcase.
+
+2014-05-07  Richard Biener  <rguenther@suse.de>
+
        PR tree-optimization/57864
        * gcc.dg/torture/pr57864.c: New testcase.
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr59330.c b/gcc/testsuite/gcc.dg/torture/pr59330.c
new file mode 100644 (file)
index 0000000..74b832e
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+
+void free(void *ptr)
+{
+}
+
+void *foo(void)
+{
+  return 0;
+}
+
+int main(void)
+{
+  void *p = foo();
+  free(p);
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr59715.c b/gcc/testsuite/gcc.dg/torture/pr59715.c
new file mode 100644 (file)
index 0000000..19c09de
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+int a = 2, b;
+
+int
+main ()
+{
+  int c;
+  if (!b)
+    {
+      b = a;
+      c = a == 0 ? 1 : 1 % a;
+      if (c)
+       b = 0;
+    }
+  if (b != 0)
+    abort ();
+  return 0;
+}
index c4a1ffa..cfdf7aa 100644 (file)
@@ -109,7 +109,6 @@ static int locus_map_eq (const void *, const void *);
 static void assign_discriminator (location_t, basic_block);
 static edge gimple_redirect_edge_and_branch (edge, basic_block);
 static edge gimple_try_redirect_by_replacing_jump (edge, basic_block);
-static unsigned int split_critical_edges (void);
 
 /* Various helpers.  */
 static inline bool stmt_starts_bb_p (gimple, gimple);
@@ -7399,7 +7398,7 @@ struct cfg_hooks gimple_cfg_hooks = {
 
 /* Split all critical edges.  */
 
-static unsigned int
+unsigned int
 split_critical_edges (void)
 {
   basic_block bb;
index d99e771..bb1ef08 100644 (file)
@@ -1310,26 +1310,19 @@ eliminate_unnecessary_stmts (void)
          stats.total++;
 
          /* We can mark a call to free as not necessary if the
-            defining statement of its argument is an allocation
-            function and that is not necessary itself.  */
-         if (gimple_call_builtin_p (stmt, BUILT_IN_FREE))
+            defining statement of its argument is not necessary
+            (and thus is getting removed).  */
+         if (gimple_plf (stmt, STMT_NECESSARY)
+             && gimple_call_builtin_p (stmt, BUILT_IN_FREE))
            {
              tree ptr = gimple_call_arg (stmt, 0);
-             tree callee2;
-             gimple def_stmt;
-             if (TREE_CODE (ptr) != SSA_NAME)
-               continue;
-             def_stmt = SSA_NAME_DEF_STMT (ptr);
-             if (!is_gimple_call (def_stmt)
-                 || gimple_plf (def_stmt, STMT_NECESSARY))
-               continue;
-             callee2 = gimple_call_fndecl (def_stmt);
-             if (callee2 == NULL_TREE
-                 || DECL_BUILT_IN_CLASS (callee2) != BUILT_IN_NORMAL
-                 || (DECL_FUNCTION_CODE (callee2) != BUILT_IN_MALLOC
-                     && DECL_FUNCTION_CODE (callee2) != BUILT_IN_CALLOC))
-               continue;
-             gimple_set_plf (stmt, STMT_NECESSARY, false);
+             if (TREE_CODE (ptr) == SSA_NAME)
+               {
+                 gimple def_stmt = SSA_NAME_DEF_STMT (ptr);
+                 if (!gimple_nop_p (def_stmt)
+                     && !gimple_plf (def_stmt, STMT_NECESSARY))
+                   gimple_set_plf (stmt, STMT_NECESSARY, false);
+               }
            }
 
          /* If GSI is not necessary then remove it.  */
index 19cacfc..0222dac 100644 (file)
@@ -636,7 +636,7 @@ static void
 execute_sink_code (void)
 {
   loop_optimizer_init (LOOPS_NORMAL);
-
+  split_critical_edges ();
   connect_infinite_loops_to_exit ();
   memset (&sink_stats, 0, sizeof (sink_stats));
   calculate_dominance_info (CDI_DOMINATORS);