]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/19831 (Missing DSE/malloc/free optimization)
authorRichard Guenther <rguenther@suse.de>
Thu, 8 Sep 2011 09:21:39 +0000 (09:21 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 8 Sep 2011 09:21:39 +0000 (09:21 +0000)
2011-09-08  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/19831
* tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Do not mark
allocation functions as necessary.

* gcc.dg/tree-ssa/ssa-dce-8.c: New testcase.

From-SVN: r178683

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-8.c [new file with mode: 0644]
gcc/tree-ssa-dce.c

index d7fc0f014bfdf573bcf1a59479df7a0347444329..f4416030d23c1c91d2f35123114a7e840c6dd0fb 100644 (file)
@@ -1,3 +1,9 @@
+2011-09-08  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/19831
+       * tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Do not mark
+       allocation functions as necessary.
+
 2011-09-08  Iain Sandoe  <iains@gcc.gnu.org>
 
        *config/darwin-driver.c (darwin_find_version_from_kernel): New routine 
index 18b487d063c312bf88f0bbfe2bb2a6c69bc8dbd9..b432683ced97eb67902b48a8f988ddf614481462 100644 (file)
@@ -1,3 +1,8 @@
+2011-09-08  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/19831
+       * gcc.dg/tree-ssa/ssa-dce-8.c: New testcase.
+
 2011-09-08  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/44646
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-8.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-8.c
new file mode 100644 (file)
index 0000000..689eb99
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+int main()
+{
+  int *p = __builtin_malloc (4);
+  *p = 4;
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "malloc" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
index c9ad3117eb8fc62604f2c40ab075cf43deaa518d..e29f3659be8b753b6dfeb5fb1df197c31943b59e 100644 (file)
@@ -299,17 +299,29 @@ mark_stmt_if_obviously_necessary (gimple stmt, bool aggressive)
       return;
 
     case GIMPLE_CALL:
-      /* Most, but not all function calls are required.  Function calls that
-        produce no result and have no side effects (i.e. const pure
-        functions) are unnecessary.  */
-      if (gimple_has_side_effects (stmt))
-       {
-         mark_stmt_necessary (stmt, true);
+      {
+       tree callee = gimple_call_fndecl (stmt);
+       if (callee != NULL_TREE
+           && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
+         switch (DECL_FUNCTION_CODE (callee))
+           {
+           case BUILT_IN_MALLOC:
+           case BUILT_IN_CALLOC:
+           case BUILT_IN_ALLOCA:
+             return;
+           }
+       /* Most, but not all function calls are required.  Function calls that
+          produce no result and have no side effects (i.e. const pure
+          functions) are unnecessary.  */
+       if (gimple_has_side_effects (stmt))
+         {
+           mark_stmt_necessary (stmt, true);
+           return;
+         }
+       if (!gimple_call_lhs (stmt))
          return;
-       }
-      if (!gimple_call_lhs (stmt))
-        return;
-      break;
+       break;
+      }
 
     case GIMPLE_DEBUG:
       /* Debug temps without a value are not useful.  ??? If we could