cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CUBEIDE Optimisation appears rather random

MikeDB
Lead

I have optimisation set to -o2 and every other Property and Preference is default. Processor is a H750. My code has a time critical inner loop which seems to vary from 14 up to 26 instructions for the same code, varying solely on the time of day when it was compiled. Is there something random in the way the compiler begins its optimisation and if so is this something I can turn off ?

4 REPLIES 4
MikeDB
Lead

Solved sort of if anyone else has a similar problem. There appears to be some randomness in the order entries are made in the indirection table after each subroutine, and as the whole function was quite large this in turn was creating a cascade effect on how these indirection values were accessed from my inner loop. Moving the inner loop to its own function solved the problem. Obviously this adds a function call but the inner loop (now 13 instructions !) is performed 10 times for each call so its a huge gain. I would have thought the compiler could have noticed this problem and done this itself.

Markus GIRDLAND
ST Employee

Are you able to extract the code that gives different results?

Could you send that piece of the code to me so I can try to replicate?

Sounds very weird, our test suites were ran successfully and we have not received any similar reports.

MikeDB
Lead

Problem is as soon as I extract a code segment, it compiles correctly. I assume it's some sort of code size/position dependancy. Let me see if I can create something not too large that shows the problem. How do I send code directly to you ?

Markus GIRDLAND
ST Employee

You should be able to click my name to go to my profile and there you can send "Message" to send it privately to me. Alternatively my mail is listed there as well.