Functions that are CSEable but not pure

Jason Merrill jason@redhat.com
Thu Oct 11 16:17:00 GMT 2012


On 10/11/2012 11:14 AM, Alexandre Oliva wrote:
> How about marking the singleton containing the call to the initializer
> as always_inline, but not the initializer itself?
>
> The compiler can then infer that initialized is set on the first inlined
> call and optimize away subsequent tests and initializer calls
> (call_some_function_that_may_modify_memory).

That would require exporting the initialized flag in addition to the 
initializer function; currently it is private to the translation unit 
with the initializer function.  That is, the wrapper currently looks like

int& i_wrap()
{
   if (i_init) i_init();
   return i;
}

and your suggestion would change it to

int& i_wrap()
{
   if (i_init && !i_initialized) { i_initialized = true; i_init(); }
   return i;
}

In previous discussions, people thought this would be less efficient.

Jason



More information about the Gcc mailing list