Hello,this patch teaches gcc that free kills the memory its argument points to. The equality test is probably too strict, I guess we can loosen it later (unless you have suggestions?).
Note that the corresponding code for BUILT_IN_MEMCPY and others seems suspicious to me, it looks like it is testing for equality between a pointer and a mem_ref, which is unlikely to happen.
Bootstrap+testsuite on x86_64-unknown-linux-gnu. 2013-10-27 Marc Glisse <marc.gli...@inria.fr> PR tree-optimization/19831 gcc/ * tree-ssa-alias.c (stmt_kills_ref_p_1): Handle BUILT_IN_FREE. gcc/testsuite/ * gcc.dg/tree-ssa/alias-25.c: New file. -- Marc Glisse
Index: gcc/testsuite/gcc.dg/tree-ssa/alias-25.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/alias-25.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/alias-25.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ + +void f (long *p) { + *p = 42; + p[4] = 42; + __builtin_free (p); +} + +/* { dg-final { scan-tree-dump-not "= 42" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ + Property changes on: gcc/testsuite/gcc.dg/tree-ssa/alias-25.c ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: gcc/tree-ssa-alias.c =================================================================== --- gcc/tree-ssa-alias.c (revision 204088) +++ gcc/tree-ssa-alias.c (working copy) @@ -2053,20 +2053,30 @@ stmt_kills_ref_p_1 (gimple stmt, ao_ref } } if (is_gimple_call (stmt)) { 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_FREE: + { + tree ptr = gimple_call_arg (stmt, 0); + tree base = ao_ref_base (ref); + if (base && TREE_CODE (base) == MEM_REF + && TREE_OPERAND (base, 0) == ptr) + return true; + break; + } + case BUILT_IN_MEMCPY: case BUILT_IN_MEMPCPY: case BUILT_IN_MEMMOVE: case BUILT_IN_MEMSET: case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMPCPY_CHK: case BUILT_IN_MEMMOVE_CHK: case BUILT_IN_MEMSET_CHK: { tree dest = gimple_call_arg (stmt, 0);