SPRU514Z July 2001 – October 2023 SM320F28335-EP
The post-link optimizer optimizes DP loads after a call to a function if the function is defined in the same file scope. For example, consider the following post-link optimized code:
_main:
LCR #_foo
MOVB AL, #0
;<<REDUNDANT>> MOVZ DP,#_g2
MOV @_g2, #20
LRETR
.global _foo
_foo:
MOVZ DP, #g1
MOV @_g1, #10
LRETR
The MOVZ DP after the function call to _foo is removed by the post-link optimizer as the variables _g1 and _g2 are in the same page and the function _foo already set the DP.
In order for the post-link optimizer to optimize across the function calls, the functions should have only one return statement. If you are running the post-link optimizer on hand written assembly that has more than one return statement per function, the post-link optimization output can be incorrect. You can turn off the optimization across function calls by specifying the -nf option after the -plink option.