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/MSP430FR6820: Optimization, eliminating local common expressions

Expert 5920 points
Part Number: MSP430FR6820

Tool/software: TI C/C++ Compiler

Hello team,

we are working on code optimization. Currently using -O0 level of optimization (page 55, SLAU132R), but since we are limited on memory, we may need to change to -O1 level.

That level contains "Eliminates local common expressions" optimization.

Question, is there any additional explanation available, what does this particular optimization really do (examples?)? Should we be afraid of inconsistent functions, etc.?

Thank you

  • Please search the MSP430 compiler manual for the sub-chapter titled Data Flow Optimizations.  The phrase eliminates local common expressions refers to performing common subexpression elimination within basic blocks.  

    For example, something like this ...

    /* C-like pseudo-code */
    a = b + c;
    /* a few lines later, inside the same loop or if block */
    d = b + c;

    ... gets optimized into ...

    temp = b + c;
    a = temp;
    /* a few lines later */
    d = temp;

    Bart said:
    Should we be afraid of inconsistent functions, etc.?

    The first rule of any optimization is that it must compute the same result as the original source code.

    Thanks and regards,


**Attention** This is a public forum