[RFC][PATCH] Extend DCE to remove unnecessary new/delete-pairs

Martin Sebor msebor@gmail.com
Wed Nov 29 08:13:00 GMT 2017


On 11/27/2017 02:22 AM, Dominik Inführ wrote:
> Thanks for all the reviews! IÂ’ve revised the patch, the operator_delete_flag is now stored in tree_decl_with_vis (there already seem to be some FUNCTION_DECL-flags in there). IÂ’ve also added the option -fallocation-dce to disable this optimization. It bootstraps and no regressions on aarch64 and x86_64.
>
It's great to be able to eliminate pairs of these calls.  For
unpaired calls, though, I think it would be even more useful to
also issue a warning.  Otherwise the elimination will mask bugs
that might only show up without optimization, or with other
compilers (such as older versions of GCC).  I realize GCC doesn't
warn for these bugs involving malloc, but I think it should for
the same reason.

> The problem with this patch is what Marc noticed: it omits too many allocations. The C++ standard seems to only allow to omit "replaceable global allocation functions (18.6.1.1, 18.6.1.2)”. So e.g. no class-specific or user-defined allocations. I am not sure what’s the best way to implement this. Just checking the function declarations might not be enough and seems more like a hack. The better way seems to introduce a __builtin_operator_new like Marc mentioned. In which way would you implement this? Could you please give me some pointers here to look at?

I'm not sure there is a way to do it other than by comparing
the name.  To see where to insert the built-in and when, you
might want to look at cp/init.c.

Martin

>
> Thanks,
> Dominik
>
>
>
>
>> On 22 Nov 2017, at 11:37, Jakub Jelinek <jakub@redhat.com> wrote:
>>
>> On Wed, Nov 22, 2017 at 10:30:29AM +0100, Richard Biener wrote:
>>> --- a/gcc/tree-core.h
>>> +++ b/gcc/tree-core.h
>>> @@ -1787,7 +1787,9 @@ struct GTY(()) tree_function_decl {
>>>   unsigned has_debug_args_flag : 1;
>>>   unsigned tm_clone_flag : 1;
>>>   unsigned versioned_function : 1;
>>> -  /* No bits left.  */
>>> +
>>> +  unsigned operator_delete_flag : 1;
>>> +  /* 31 bits left.  */
>>>
>>> while it looks bad reality is that on 64bit pointer hosts we had 32 bits left.
>>
>> But we can just add it to say tree_decl_common which has 14 spare bits or
>> tree_decl_with_vis which has another 14 spare bits.  By just noting the flag
>> applies only to FUNCTION_DECLs and enforcing it in the tree.h macros,
>> it will be easy to reuse that bit for something different for trees other
>> than FUNCTION_DECL.
>>
>> 	Jakub
>



More information about the Gcc-patches mailing list