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

When does arm-none-eabi-gcc optimize away empty loops?

I am used to gcc optimizing away the sort of "for (i=0; i<DELAYCOUNT; i++) ;" loops that people sometimes try to use for delays.

But arm gcc seems to be very inconsistent in this area.

the following code, compiled with arm-gcc version 5.4, 6, 8, 9, or 10 and -Os, -O2, or -O3 will optimize away the loop in delay(), but NOT the for loop in main() ??

arm gcc 7 optimizes away both loops. g++ optimizes away both loops.

 

from gcc 10:

(I'm not happy about the extra "cmp" instruction, either.  The subs will have set the flags.  with cpu=cortex-m4 it does better.)

0