malloc cannot alias preexisting pointers
Richard Sandiford
richard.sandiford@arm.com
Sun May 12 11:33:00 GMT 2019
Marc Glisse <marc.glisse@inria.fr> writes:
> Hello,
>
> this patch lets gcc know that if a pointer existed before the call to
> malloc, the result of malloc cannot alias it. This is a bit ad hoc and
> fragile. A small improvement would be, when the 2 statements are in the
> same bb but in the wrong order, to check if there is any statement in
> between that might prevent from reordering them. But that's more
> complicated, and the patch as it is already does help.
>
> I expect people may not like the call to a function from
> tree-ssa-loop-niter too much, but it is convenient. And if someone
> improves it, they will likely have to rewrite something not quite
> equivalent to stmt_dominates_stmt_p.
It has linear complexity for statements in the same block though.
(reassoc_stmt_dominates_stmt_p avoids that, but relies on uids
being up-to-date.)
> The testcase uses libstdc++ quite a bit. I thought about putting it in the
> libstdc++ testsuite, but it does not know scan-tree-dump, and in the
> assembly it may be too late, memcpy may get expanded to something
> target-specific. So it is in g++.dg. I could write a more artificial
> testcase, but the behavior of std::vector is really what I want to test...
>
> Bootstrap+regtest on x86_64-pc-linux-gnu.
>
> 2019-05-13 Marc Glisse <marc.glisse@inria.fr>
>
> gcc/
> * tree-ssa-loop-niter.c (stmt_dominates_stmt_p): Handle NULL
> basic block.
> * tree-ssa-alias.c: Include tree-ssa-loop-niter.h.
> (ptr_derefs_may_alias_p): Detect malloc and an older pointer.
>
> gcc/testsuite/
> * g++.dg/tree-ssa/ldist-2.C: New file.
More information about the Gcc-patches
mailing list