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


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.

Ian


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