ARM Cortex-M Broken Binaries with -O2 and -O3 (-fschedule-insns)

Johannes Pfau via D.gnu d.gnu at puremagic.com
Sat Jul 22 01:15:45 PDT 2017


Am Fri, 21 Jul 2017 23:44:53 +0000
schrieb Mike <none at none.com>:

> My stm32 demo has now been updated and working with GDC/GCC 
> 7.1.0.  Thanks for all your improvements.
> 
> However, I'm getting broken binaries with -O2 and -O3.  I've 
> nailed the culprit down to -fschedule-insns (i.e. if I add 
> -fno-schedule-insns to -O2 or -O3, the binary works fine).
> 
> I disassembled '-O2' and '-O2 -fno-schedule-insns' and compared 
> them, but they were quite different all the way through.  No only 
> because of address locations, but also different registers and 
> even different opcodes.  (e.g. 'str r2, [sp, #12]' vs 'strd r1, 
> r2, [sp, #8]')

This can unfortunately happen if scheduling allows further
optimizations. Then the generated code might look nothing like the
original code. It's also possible that this is only caused by a
combination of optimization passes, I guess it doesn't happen using
-fschedule-insns without other -O flags?

> 
> Is there anything I can do to provide more actionable information 
> to help identify the underlying cause?

As I don't have an ARM bare metal compiler ready to test: The output of
-fdump-tree-all and -fdump-rtl-all would be useful. The tree output is
usually quite readable, rtl not so much...

There might be some more useful switches on
https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html

-- Johannes



More information about the D.gnu mailing list