MSP-CGT: Potential optimisation in MSP430 C compiler

Part Number: MSP-CGT


Hello,

First of all, sorry for not putting this into MSP microcontrollers forum - the MSP-CGT seems to be under (incorrect?) ARM-based MCUs...

I think there is an opportunity for a small optimisation of the following C snippet. After checking the return value of function "boolean_test_func" (in register R12), the generated instructions should not need to clear R12 before returning from "func" as this has already been cleared by "boolean_test_func".

bool func(...)
{
    ...
    if ( ! boolean_test_func())
    {
        return false;
    }
    ...
    return true;
}
 
Generated instructions from a similar code as the snippet above:

               func()
    ...
    0x0E066    12B0 E00E           CALL    #boolean_test_func

    0x0E06A    934C                TST.B   R12
    0x0E06C    2416                JEQ     ($C$L46)
    ...
    0x0E096    435C                MOV.B   #1,R12
    0x0E098    4130                RET     
               $C$L46
    0x0E09A    434C                CLR.B   R12
    0x0E09C    4130                RET     

The code generated could omit the last two instructions altogether and jump to the preceding RET instruction instead:

               func()
    ...
    0x0E066    12B0 E00E           CALL    #boolean_test_func

    0x0E06A    934C                TST.B   R12
    0x0E06C    2416                JEQ     ($C$L46)
    ...
    0x0E096    435C                MOV.B   #1,R12
               $C$L46
    0x0E098    4130                RET     

Four bytes saved Slight smile

Kind regards,

Michal