[ECOS] gcc(2.95 for ARM) optimize error

Andrew Lunn andrew.lunn@ascom.ch
Tue Nov 27 04:10:00 GMT 2001

On Tue, Nov 27, 2001 at 07:01:52PM +0800, james chen wrote:
> Hi,
>    I am using eCos, when I use -O0 or -O1 to compile eCos and my test
> application, it runs OK, but If I GCC optimize to -O2, it will failed. After
> check it's assembler, I find that GCC(2.95 for ARM) has changed
> application's code order and also miss some code. have anyone found this?

I've not had problems.

What sort of code is it? IO for a device driver? do you have all the
required volatiles? The compile is allowed to change the order and
remove redundant code that does nothing...


   a = *(unsigned int *)0x41000000;
   b = *(unsigned int *)0x41000008;
   a = *(unsigned int *)0x41000004;        
The compile is allowed to remove the first assignment since the result
is never used. Also it can do the b assignment first or last since the
result is not needed for the other two assignments. 

If you want to force it to keep the redundant loads and keep the order
you need to add volatile

   a = *(volatile unsigned int *)0x41000000;
   b = *(volatile unsigned int *)0x41000008;
   a = *(volatile unsigned int *)0x41000004;        

There was a discussion about all this a month or two ago on the
list. Read back in the archives.


More information about the Ecos-discuss mailing list