diff options
author | Richard Guenther <rguenther@suse.de> | 2011-09-08 13:00:23 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2011-09-08 13:00:23 +0000 |
commit | 996e1de5e6bced0c6b6b0cbacee11ccc720ccdf4 (patch) | |
tree | bcaff4692c5de5b68874b434da9ce5fdf5834598 /gcc/testsuite/gcc.dg | |
parent | c22c0db26ad16673415d7523781fcf80c8e545ba (diff) | |
download | gcc-996e1de5e6bced0c6b6b0cbacee11ccc720ccdf4.zip gcc-996e1de5e6bced0c6b6b0cbacee11ccc720ccdf4.tar.gz gcc-996e1de5e6bced0c6b6b0cbacee11ccc720ccdf4.tar.bz2 |
re PR tree-optimization/19831 (Missing DSE/malloc/free optimization)
2011-09-08 Richard Guenther <rguenther@suse.de>
PR tree-optimization/19831
* tree-ssa-dce.c (mark_all_reaching_defs_necessary_1): Also
skip builtins with vdefs that do not really store something.
(propagate_necessity): For calls to free that we can associate
with an allocation function do not mark the freed pointer
definition necessary.
(eliminate_unnecessary_stmts): Remove a call to free if
the associated call to an allocation function is not necessary.
* gcc.dg/tree-ssa/pr19831-1.c: New testcase.
* gcc.dg/tree-ssa/pr19831-2.c: Likewise.
* gcc.dg/tree-ssa/pr19831-3.c: Likewise.
* gcc.dg/errno-1.c: Adjust.
From-SVN: r178687
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r-- | gcc/testsuite/gcc.dg/errno-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr19831-1.c | 32 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr19831-2.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr19831-3.c | 39 |
4 files changed, 87 insertions, 1 deletions
diff --git a/gcc/testsuite/gcc.dg/errno-1.c b/gcc/testsuite/gcc.dg/errno-1.c index d0365be..295deef 100644 --- a/gcc/testsuite/gcc.dg/errno-1.c +++ b/gcc/testsuite/gcc.dg/errno-1.c @@ -6,7 +6,7 @@ int main() { - void *p; + void * volatile p; errno = 0; p = malloc (-1); if (errno != 0) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr19831-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr19831-1.c new file mode 100644 index 0000000..1c8f972 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr19831-1.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +void test1(void) +{ + int *p = __builtin_malloc (sizeof (int) * 4); + int *q = p; + *q++ = 4; + *q++ = 4; + __builtin_free (p); +} + +void test3(int b) +{ + int *p = __builtin_malloc (sizeof (int) * 4); + if (b) + __builtin_free (p); + *p = 5; +} + +void test4(int b) +{ + int *p = __builtin_malloc (sizeof (int) * 4); + if (b) + __builtin_free (p); + *p = 5; + __builtin_free (p); +} + +/* { dg-final { scan-tree-dump-times "free" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "malloc" 0 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr19831-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr19831-2.c new file mode 100644 index 0000000..bc7c4cc --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr19831-2.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +void test1(void) +{ + int *p = __builtin_malloc (sizeof (int) * 4); + *p++ = 4; + __builtin_free (p); +} + +/* Undefined. We can't do anything here. */ + +/* { dg-final { scan-tree-dump-times "free" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "malloc" 1 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr19831-3.c b/gcc/testsuite/gcc.dg/tree-ssa/pr19831-3.c new file mode 100644 index 0000000..02b5572 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr19831-3.c @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +void test2(void) +{ + int *p = __builtin_malloc (sizeof (int) * 4); + if (p == (void *)0) + __builtin_abort (); + __builtin_free (p); +} + +void test5(int b) +{ + int *p = __builtin_malloc (sizeof (int) * 4); + if (p) + __builtin_free (p); +} + +void test6(void) +{ + int *p = __builtin_malloc (sizeof (int) * 4); + if (p == (void *)0) + __builtin_abort (); + if (p) + __builtin_free (p); +} + +/* We should be able to remove all malloc/free pairs with CDDCE. + Assume p was non-NULL for test2. + For test5, it doesn't matter if p is NULL or non-NULL. */ + +/* { dg-final { scan-tree-dump-times "free" 0 "optimized" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times "malloc" 0 "optimized" { xfail *-*-* } } } */ + +/* But make sure we don't partially optimize for now. */ + +/* { dg-final { scan-tree-dump-times "free" 3 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "malloc" 3 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ |