This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [-ftree-cselim desoptimizes SH code
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: Christian BRUEL <christian dot bruel at st dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 27 Sep 2009 11:54:27 +0200
- Subject: Re: [-ftree-cselim desoptimizes SH code
- References: <4ABCA7CB.8020409@st.com> <mcrr5ttrnyf.fsf@dhcp-172-17-9-151.mtv.corp.google.com>
On Sun, Sep 27, 2009 at 6:50 AM, Ian Lance Taylor <iant@google.com> wrote:
> Christian BRUEL <christian.bruel@st.com> writes:
>
>> On SH, -ftree-cselim transforms a simple conditional store such as
>>
>> foo(int *a)
>> {
>> ? ? *a = 0;
>> ? if (bar())
>> ? ? *a = 1;
>> }
>>
>> into
>>
>> foo(int *a)
>> {
>> ? ? *a = 0;
>> ? if (! bar())
>> ? ? r = *a;
>> ? else
>> ? ? r = 1;
>>
>> ? ?*a = r;
>> }
>>
>> which is equivalent to add either a load or a store on the critical
>> path (depending if the branch is likely to be taken or not)
>
> I believe this transformation is invalid under the C++0x memory model.
> It may introduce a race condition in a multi-threaded program. ?gcc
> should never make this transformation unless it knows for sure that it
> will turn into a conditionally executed store.
Maybe in this particular case (and only because of the function call),
but in general the transformation in the end results in
*a = ! bar () ? 0 : 1;
thus it only removes a store and thus cannot add a race condition.
See also Michas mail.
Richard.
> Ian
>