This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

-O1 removes useful code

I have the following snippet of code, which toggles one of the GPIO lines:

PINSEL1 &= ~(0x0000000C);
IO0SET |= MY_GPIO_MASK;
IO0CLR |= MY_GPIO_MASK;
PINSEL1 |= 0x00000008;

This works fine as Thumb code at -O0. However, if I compile this as -O1 or higher (still Thumb), this code is optimized out and I don't get the "side effect" of my GPIO toggling.

If I switch over to generating ARM code, this works at -O0, -O1, and -O2 (i.e. no problem).

This seems really wrong. PINSEL1, IO0SET, etc. are all defined as volatile in LPC22xx.h, so shouldn't the compiler leave this alone when optimizing? Any good way of getting around this?

Parents Reply Children
No data