This is the mail archive of the gcc@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: O2 Agressive Optimisation by GCC


Hi!

On Mon, Jul 23, 2018 at 12:36:50PM +0200, David Brown wrote:
> This is nothing to do with undefined behaviour, but a matter of
> scheduling of effects that are visible in different circumstances.  In
> particular, i and j are declared in a way that tells the compiler that
> the compiler, in its current thread of execution has full control of
> them.  The compiler knows that while it is executing the code in test,
> nothing else can affect the value of i or j, nor can they be affected by
> the values of i and j.  The compiler knows that code from elsewhere may
> read or write them, but only before test() is called, during functions
> called from test(), or after test() returns.  It knows for sure that
> there are no other threads of execution that interact via i and j.

It could in theory know that, yes, but in this case it just hoists the
assignment to after the loop.  And it's an infinite loop, so it just
disappears.

> So how do you inhibit these kinds of optimisations?  Stop lying to your
> compiler.

Yup :-)


Segher


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