Re: O2 Agressive Optimisation by GCC

2018-07-23 Thread Segher Boessenkool
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 it

Re: O2 Agressive Optimisation by GCC

2018-07-23 Thread David Brown
Hi, 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

Re: O2 Agressive Optimisation by GCC

2018-07-22 Thread Allan Sandfeld Jensen
On Sonntag, 22. Juli 2018 17:01:29 CEST Umesh Kalappa wrote: > Allan , > > >>he might as well go traditional > > you mean using the locks ? > No I am meant relying on undefined behavior. In your case I would recommend using modern atomics, which is defined behavior, and modern and fast. I was

Re: O2 Agressive Optimisation by GCC

2018-07-22 Thread Umesh Kalappa
Allan , >>he might as well go traditional you mean using the locks ? Thank you ~Umesh On Sat, Jul 21, 2018 at 4:20 AM, Allan Sandfeld Jensen wrote: > On Samstag, 21. Juli 2018 00:21:48 CEST Jonathan Wakely wrote: >> On Fri, 20 Jul 2018 at 23:06, Allan Sandfeld Jensen wrote: >> > On Freitag, 20.

Re: O2 Agressive Optimisation by GCC

2018-07-22 Thread Umesh Kalappa
Hi Richard, making i unsigned still the optimization is effective ,no luck. and yes test() is the threaded routine and since i and j are global ,we need the side effects take place like assignment etc ,that are observed by other threads . By making volatile or thread safe or atomic operations

Re: O2 Agressive Optimisation by GCC

2018-07-20 Thread Allan Sandfeld Jensen
On Samstag, 21. Juli 2018 00:21:48 CEST Jonathan Wakely wrote: > On Fri, 20 Jul 2018 at 23:06, Allan Sandfeld Jensen wrote: > > On Freitag, 20. Juli 2018 14:19:12 CEST Umesh Kalappa wrote: > > > Hi All , > > > > > > We are looking at the C sample i.e > > > > > > extern int i,j; > > > > > > int t

Re: O2 Agressive Optimisation by GCC

2018-07-20 Thread Jonathan Wakely
On Fri, 20 Jul 2018 at 23:06, Allan Sandfeld Jensen wrote: > > On Freitag, 20. Juli 2018 14:19:12 CEST Umesh Kalappa wrote: > > Hi All , > > > > We are looking at the C sample i.e > > > > extern int i,j; > > > > int test() > > { > > while(1) > > { i++; > > j=20; > > } > > return 0; >

Re: O2 Agressive Optimisation by GCC

2018-07-20 Thread Allan Sandfeld Jensen
On Freitag, 20. Juli 2018 14:19:12 CEST Umesh Kalappa wrote: > Hi All , > > We are looking at the C sample i.e > > extern int i,j; > > int test() > { > while(1) > { i++; > j=20; > } > return 0; > } > > command used :(gcc 8.1.0) > gcc -S test.c -O2 > > the generated asm for x86 >

Re: O2 Agressive Optimisation by GCC

2018-07-20 Thread Martin Sebor
On 07/20/2018 12:17 PM, Richard Biener wrote: On July 20, 2018 7:59:10 PM GMT+02:00, Martin Sebor wrote: On 07/20/2018 06:19 AM, Umesh Kalappa wrote: Hi All , We are looking at the C sample i.e extern int i,j; int test() { while(1) { i++; j=20; } return 0; } command used :(gc

Re: O2 Agressive Optimisation by GCC

2018-07-20 Thread Richard Biener
On July 20, 2018 7:59:10 PM GMT+02:00, Martin Sebor wrote: >On 07/20/2018 06:19 AM, Umesh Kalappa wrote: >> Hi All , >> >> We are looking at the C sample i.e >> >> extern int i,j; >> >> int test() >> { >> while(1) >> { i++; >> j=20; >> } >> return 0; >> } >> >> command used :(gcc 8.1

Re: O2 Agressive Optimisation by GCC

2018-07-20 Thread Martin Sebor
On 07/20/2018 06:19 AM, Umesh Kalappa wrote: Hi All , We are looking at the C sample i.e extern int i,j; int test() { while(1) { i++; j=20; } return 0; } command used :(gcc 8.1.0) gcc -S test.c -O2 the generated asm for x86 .L2: jmp .L2 we understand that,the infi

Re: O2 Agressive Optimisation by GCC

2018-07-20 Thread Jakub Jelinek
On Fri, Jul 20, 2018 at 05:49:12PM +0530, Umesh Kalappa wrote: > We are looking at the C sample i.e > > extern int i,j; > > int test() > { > while(1) > { i++; > j=20; > } > return 0; > } > > command used :(gcc 8.1.0) > gcc -S test.c -O2 > > the generated asm for x86 > > .L2: >

O2 Agressive Optimisation by GCC

2018-07-20 Thread Umesh Kalappa
Hi All , We are looking at the C sample i.e extern int i,j; int test() { while(1) { i++; j=20; } return 0; } command used :(gcc 8.1.0) gcc -S test.c -O2 the generated asm for x86 .L2: jmp .L2 we understand that,the infinite loop is not deterministic ,compiler is fr