There is a minor regression with ZP usage in SDCC 4.5.0 compared to 4.4.0
The attached C program (which can be run in the SDCC test suite) will result in one 16-bit temporary variable allocated to the "ZP" segment:
r14650:
;--------------------------------------------------------
; ZP ram data
;--------------------------------------------------------
.area _ZP (PAG)
Lsdcc_zp_regression.func$sloc0$0_1$0==.
_func_sloc0_1_0:
.ds 2
r15263:
;--------------------------------------------------------
; ZP ram data
;--------------------------------------------------------
.area _ZP (PAG)
Lsdcc_zp_regression.func$sloc0$0_1$0==.
_func_sloc0_1_0:
.ds 2
Lsdcc_zp_regression.func$sloc1$0_1$0==.
_func_sloc1_1_0:
.ds 2
The extra temp is from different icode sequences fed to the codegen.
For the suboptimal case (just compiled with the current svn), the address of
array[array_index]is computed intosloc0_1_0.Then it is copied to
sloc1_1_0for every single use.This is not only wasteful of ZP space is also wasteful for performance.
Ideally the higher level optimizer would realize that
sloc0_1_0is not modified by any of the code, so it can be used directly.