On Thu, 2024-10-31 at 17:06 +0100, Jan Hubicka wrote:
> Hi,
> this patch lets us to remove
>   void *mem = __builtin_malloc (s);
>   if (!mem)
>     __builtin_abort ();
>   __builtin_free (mem);
> 
> Where we previously stopped on "if (!mem)" marking __builtin_malloc
> necessary.
> This is done by matching such conditional in tree-ssa-dce.cc and
> playing same game
> as we do for free functions.  We consider if itself necessary (since
> it does
> control flow) but we do not propagate necessity over the SSA name.
> 
> In removal stage we check whether SSA name is needed and if not, we
> replace
> it by constant 1, which makes the conditonal to be folded as constant
> in
> cfgccleanup.
> 
> While working on this, I refactored the code a bit to avoid duplicate
> matching
> of allocation functions which made me notice that we handled
> strdup/strndup just
> half way and this prevented us from removing it, which is also fixed
> and tested
> in the testcase.
> 
> Note that testcase pr68078.f90 checks that failed allocation is
> reported
> when memory limits are set.  We no longer report it since the memory
> is
> unused and that is why I needed to disable DCE.
> 
> I alos tested that with Jakub's patch we now eliminate new operator
> with
> std::nothrow_t.
> 
> Bootstrapped/regtested x86_64-linux, OK?

I have a vague memory that one of the tests in SPEC has a loop that
tries to malloc, doubling the size each time, until it fails.  Would
the patch change the behavior of such a loop?

Sorry, I can't remember further details.
Dave

Reply via email to