Functions that are CSEable but not pure

Jason Merrill jason@redhat.com
Thu Oct 4 12:56:00 GMT 2012


On 10/04/2012 08:45 AM, Jakub Jelinek wrote:
> On Thu, Oct 04, 2012 at 10:42:59AM +0200, Richard Guenther wrote:
>> On Wed, Oct 3, 2012 at 9:00 PM, Jason Merrill <jason@redhat.com> wrote:
>> If the result is not needed, are we allowed to remove a call to this
>> function?
>
> No.  Unless you know the same function has been already called.

Yes, we are.  If we optimize away a use of the variable, we can also 
remove the call to the function.  We can also hoist the call so its 
side-effects occur before other side-effects, as the standard only 
requires that the initialization of the variable occur some time between 
thread creation and the first use of the variable.

>> So - what's wrong with using pure?  That it doesn't "feel" correct?
>
> No, it can modify memory.

Right, that's the issue.  The back end assumes that calls to pure 
functions won't clobber memory; calls to these functions can clobber 
arbitrary memory, but only on the first call.

> I think the plan was for these functions not to return any value,

No, I'm talking about the wrapper function which returns a reference to 
the variable (as in my example).

Jason



More information about the Gcc mailing list