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.

Compiler/TMS320F2808: C2000 : optimization level -02

Part Number: TMS320F2808

Tool/software: TI C/C++ Compiler

Hello

In one of our products we recently changed the compiler C2000 version from 3.09 to v6.4 for which the only significant change with regards to the previous version in terms of compiler switches is related with optimization (in both using -O2 level). The new version adds loops unrolling (SPRU514H page 55 shows compiler options for -O2).
My question is, can one optimization option be disabled within a particular optimization level?

In this case disable loop unrolling while still using -O2.

Best Regards
Bob Bacon 

  • Overall, unrolling is controlled by the --opt_for_speed compiler option. --opt_for_speed=2, 1, or 0 will inhibit unrolling completely. --opt_for_speed=3 might unroll cautiously (I'm not 100% certain what C2000 does). --opt_for_speed=4 is the default, and will unroll fairly aggressively because it is focused on speed rather than size. --opt_for_speed=5 is even more aggressive.

    In the source code itself, you can add "#pragma UNROLL(1)" ahead of an individual loop to inhibit its unrolling, or give different numbers to control exactly how it unrolls.
  • Thanks for your feedback on this topic, it looks like this is sort of what we were looking for.

    However, we are still unsure how this impacts on the use of optimization level 2 (-O2).

    In essence what we wanted is to get the optimization options highlighted in green while excluding the one in red.

     

    • --opt_level=off or -Ooff

    – Performs no optimization

    • --opt_level=0 or -O0

    – Performs control-flow-graph simplification

    – Allocates variables to registers

    – Performs loop rotation

    – Eliminates unused code

    – Simplifies expressions and statements

    – Expands calls to functions declared inline

    • --opt_level=1 or -O1

    Performs all --opt_level=0 (-O0) optimizations, plus:

    – Performs local copy/constant propagation

    – Removes unused assignments

    – Eliminates local common expressions

    • --opt_level=2 or -O2

    – Performs all --opt_level=1 (-O1) optimizations, plus:

    – Performs loop optimizations

    – Eliminates global common subexpressions

    – Eliminates global unused assignments

    – Performs loop unrolling

     

    From your earlier reply we understand we could optimize for speed in such a way that eventually we could get rid of loop unrolling, but how does this affect the other optimization options?

    Can this be used along with a certain optimization level (for instance -O2)?

     

    Regards
    Bob Bacon

  • No, there is no command-line option to specifically to disable unrolling independently of other size/speed tradeoffs.

    What problem is unrolling causing you?
  • This is an Avionics project that involves a great deal of software verification and certification.

    So the issue is related with backward compatibility and trying to save some efforts in terms of analysis…

    Regards
    Bob Bacon

  • --opt_for_speed can be thought of as modulating --opt_level, by indicating that you want to prefer speed or code size while using a given level. --opt_level=2 --opt_for_speed=2, which seems to be where we're heading, will do the usual -O2 optimisations, but will avoid some cases that tend to increase code size. In particular, it inhibits unrolling, but it will also refrain from some specific subsets of what it does for divides, CSE, and control-flow. (On other targets, but not C2000, it also affects how much inlining is done.)

    We don't have options that control the specific passes individually.

    If you *really* want to avoid unrolling, you might consider the 6.2.11 release, since unrolling was first enabled for 6.4.x. Both are old, though; the oldest fully-supported release is 15.12.x.