This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix missed DSE opportunity with operator delete.
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Mikhail Maltsev <maltsevm at gmail dot com>
- Cc: gcc-patches mailing list <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 18 Apr 2016 11:14:15 +0200
- Subject: Re: [PATCH] Fix missed DSE opportunity with operator delete.
- Authentication-results: sourceware.org; auth=none
- References: <5712AF84 dot 5080002 at gmail dot com>
On Sat, Apr 16, 2016 at 11:32 PM, Mikhail Maltsev <maltsevm@gmail.com> wrote:
> Hi, all!
>
> Currently GCC can optimize away the following dead store:
>
> void test(char *x)
> {
> *x = 1;
> free(x);
> }
>
> but not this one (Clang handles both cases):
>
> void test(char *x)
> {
> *x = 1;
> delete x;
> }
>
> The attached patch fixes this by introducing a new __attribute__((free)). I
> first tried to add new built-ins for each version of operator delete (there are
> four of them), but it looked a little clumsy, and would require some special
> handling for warning about taking address of built-in function.
>
> Is such approach (i.e. adding a new attribute) OK? Bootstrapped and regtested on
> x86_64-pc-linux-gnu.
Enlarging tree_function_decl is bad. I think as you made this a decl attribute
it won't work for virtual delete methods which are called indirectly.
Passes should get at the info via flags_from_decl_or_type () and a new
ECF_FREE.
Richard.
> --
> Regards,
> Mikhail Maltsev
>
> gcc/c/ChangeLog:
>
> 2016-04-16 Mikhail Maltsev <maltsevm@gmail.com>
>
> * c-decl.c (merge_decls): Handle free_flag.
>
> gcc/ChangeLog:
>
> 2016-04-16 Mikhail Maltsev <maltsevm@gmail.com>
>
> * builtin-attrs.def: Add attribute free.
> * builtins.def (free): Add attribute free.
> * doc/extend.texi: Document attribute free.
> * gtm-builtins.def (_ITM_free): Add attribute free.
> * tree-core.h (struct tree_function_decl): Add free_flag.
> * tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle free_flag.
> (call_may_clobber_ref_p_1): Likewise.
> (stmt_kills_ref_p): Likewise.
> * tree-streamer-in.c (unpack_ts_function_decl_value_fields): Likewise.
> * tree-streamer-out.c (pack_ts_function_decl_value_fields): Likewise.
> * tree.h (DECL_IS_FREE): New accessor macro.
>
> gcc/testsuite/ChangeLog:
>
> 2016-04-16 Mikhail Maltsev <maltsevm@gmail.com>
>
> * g++.dg/opt/op-delete-dse.C: New test.
> * gcc.dg/attr-free.c: New test.
>
> gcc/c-family/ChangeLog:
>
> 2016-04-16 Mikhail Maltsev <maltsevm@gmail.com>
>
>
>
> * c-common.c (handle_free_attribute): New function.
>
>
>
>
>
> gcc/cp/ChangeLog:
>
>
>
>
>
> 2016-04-16 Mikhail Maltsev <maltsevm@gmail.com>
>
>
>
>
>
> * decl.c (cxx_init_decl_processing): Set flag_free for operator delete.