optimization differences between cmd line and code declarations

Asked by Ruediger R. Asche

Apparently optimzations work differently when putting the -O<xxx> in the cmd line and into the code. This is version 4.7.4. (the current version supported by my tool vendor iSystem). Copy-and-paste the following code into a standalone C file and include it in any project with no -O option in the command line:

/***********************************************************************************************************/

//#pragma GCC optimize ("Ofast")

unsigned long Fibonacci(unsigned long p_Arg)
//unsigned long __attribute__ ((optimize("Ofast"))) Fibonacci(unsigned long p_Arg)
{
    switch(p_Arg)
    {
    case 0:
    case 1: return p_Arg;
    default: return Fibonacci(p_Arg-1)+Fibonacci(p_Arg-2);
    };
}

/***********************************************************************************************************/

In the second step, uncomment either the pragma or __attribute___ lines and rebuild. The resulting code will (expectedly) be different. In the third step, re-start from the original code (leaving all the commented lines commented) but add the option -Ofast to the command line. The code will be different from step 2, implying that -Ofast means different things when invoked from the command line and within the code.

Is this behavior by design and/or documented anywhere? Apologies if this should have been addressed before, I scanned all QAs regarding optimizations and couldn't find any reference.

Thanks!

Edit Feb 19, 2016: It appears that the optimization is done when -Ofast is within the source file and not the cmd line is the same performed as when -O2 is selected.

Edit Feb. 28, 2016: Reopened due to its still applicability. This is pretty severe in my opinion and possibly trivial to solve, in any case easy to reproduce, why are there no takers? Thanks!

Question information

Language:
English Edit question
Status:
Expired
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Ruediger R. Asche (rac-j) said :
#2

dit Feb. 28, 2016: Reopened due to its still applicability. This is pretty severe in my opinion and possibly trivial to solve, in any case easy to reproduce, why are there no takers? Thanks!

Revision history for this message
Launchpad Janitor (janitor) said :
#3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Andre Vieira (andre-simoesdiasvieira) said :
#4

Hi Ruediger,

Sorry for the delay, this must have fallen through the cracks. I can confirm this behavior is reproduceable with our current toolchain too. We will try to look into this. Thank you for reporting!

Cheers,
Andre