This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C2000: Does have any effect on the code if opt_level=off?

Guru 19935 points

Hello,

I noticed opt_for_speed is still on the command line even though opt_level=off.

Does opt_for_speed have any effect on the code if opt_level=off?  

If it does, how do I remove the opt_for_speed option?

Stephen

  • stevenh said:
    Does opt_for_speed have any effect on the code if opt_level=off?  

    I'm pretty sure it does.  Though the effect is likely to be less noticeable with no optimization.  I'll have to confirm all this and get back to you.

    stevenh said:
    If it does, how do I remove the opt_for_speed option?

    The trade-off between size and speed is always present.  Thus it does not make sense to turn it off.  If you do not use the --opt_for_speed option at all, then the compiler defaults to --opt_for_speed=2.

    Thanks and regards,

    -George

  • When the optimization level is off, that means the Optimizer component of the compiler tool chain is never invoked.  The Optimizer performs high-level optimizations.  However, a compiler makes all sorts of decisions in the process of generating machine code.  Many of these decisions occur in the back end as part of the process of generating machine code.  The --opt_for_speed option is really to specify the tradeoff preference between  code size and performance.  It does have an effect even when high-level optimization is off, but it is unlikely one would see any performance benefits when optimization is disabled.  With optimization disabled, your best bet is to prioritize code size and set --opt_for_speed to 0.  Inside CCS, to see if this setting has any impact on your project, you could use the Optimizer Assistant to automatically generate all the opt_for_speed variants and see the code size differences in the resulting graph.

  • Ok.

    Page 55 of  the TMS320C28x Optimizing C/C++ Compiler v6.4 has the following:  

    --opt_level=off or -Ooff
          – Performs no optimization

    Does that mean the --opt_level=off description is incorrect.

    Also, according to page 66 of the user guide, --opt_for_speed=2 doesn't exactly eliminate optimization.

    --opt_for_speed=2
    Enables optimizations geared towards improving the code size with a low risk of worsening or
    impacting performance.

    Stephen

  • As I tried to explain, "optimization" refers to the high-level optimizations that the Optimizer component of the compiler tool chain performs. When --opt_level=off, the Optimizer is not invoked at all by the tool chain. Thus none of those optimizations occur.

    However, the process of a compiler generating machine code involves many decisions that impact the code that is generated. The --opt_for_speed setting can still impact some of these back end decisions. The option name is somewhat outdated and should really be something like "size_versus_speed_tradeoff". However, changing option names is not easy for backwards compatibility reasons. At higher levels, this setting does indeed enable optimization passes in the Optimizer. However, when the Optimizer is not used at all (--opt_level=off), this doesn't affect optimization passes. It can still, however, affect some back end decisions. Therefore, it is unlikely to have a huge impact when optimization is off, but there might still be some code size growth at higher levels depending on the project. You can easily see if that is the case for your project using the Optimizer Assistant. I tried it out with --opt_level=off for one project I had handy, and I saw a 75-byte increase at level -mf2 and above.
  • Hello Anna,

    There might be some situations that someone might want to disable optimization altogether.  

    optimizing for speed could cause code to be removed or registers/stack to be used instead of  place of memory.  Similar things could be said about optimizing for space.

    Is the opt_for_speed and opt_for_space only available in the the C2000 compiler?  I don't remember it being in the gnu compiler.

    When was the opt_for_speed and opt_for_space added to the compiler?

    If the  opt_for_speed and opt_for_space wasn't always an option, was the size vs speed tradeoff always a part of the compiler?

    Stephen

  • --opt_for_speed and --opt_for_space are in all the TI-produced compilers. Those specific options are not in the GNU compiler, which is a different toolset. These options have existed for quite a while, with different names, but the exact form has changed over time. I don't have a copy of the C2000 compiler prior to 4.1.0, but 4.1.0 (circa 2005) has the option -ms to "optimize for code size" and the option -mf "optimize for speed." There's no "maximally pessimal" option, but by using -Ooff to disable high-level optimizations, we'll only do optimizations that are very safe and stable. In that case, typically all variables have a memory location and the value will actually reside there.
  • If you want to turn off optimization altogether, set --opt_level=off.

    When --opt_level=off, NO OPTIMIZATION OCCURS.

    The options opt_for_speed and opt_for_space ONLY AFFECT OPTIMIZATION WHEN THE OPTIMIZER IS ENABLED (--opt_level=0+).

    The option --opt_for_space is the same as --opt_for_speed=0. The --opt_for_speed is really a size-speed trade-off specification in which 0 means prefer size completely over speed (=--opt_for_space) and 5 means prefer speed completely over size, and in between should be a gradation.

    These options do not affect any of the factors you mention (code elimination or register vs. memory use). When optimization is turned off, they DO NOT AFFECT OPTIMIZATION DECISIONS. When optimization is turned off, they might still affect a few code generation decisions that are made in the compiler back-end.

    For example, if for the same source language construct, we could select between a smaller set of code instructions that took longer to run, or a longer set of code instructions that ran faster, we might make that decision based on this option. There are not many such considerations for C2000 due to its architectural features.

    These are not new options in TI's compilers and they are not specific to C2000. However, in the more recent compiler versions we have been trying to make them work better for C2000. There is still further work to be done in getting a smoother gradation of size to speed improvements. C2000 has a lot of architectural features that complicate a smooth curve. Additionally, run-time performance is dependent on some factors that the compiler can't predict, such as memory wait-states, program inputs, etc.

    Additionally, our compiler documentation needs to be updated with more thorough explanations. Ideally, the opt_for_space option would be eliminated and the opt_for_speed would change to size_speed_goal (or something like that.)

    Hope that helps.