This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [-ftree-cselim desoptimizes SH code


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
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]