sdcc version: 4.5.0 #15242 (Linux)
Consider the attached file compiling to z80 as:
sdcc -mz80 --opt-code-speed -c main.c
Then compare both functions, the function that access the global/static var directly will generate the worst scenario in performance and size by accessing it through (IY), while the second one accessing the same vars but using a pointer will get a much better code using the register HL.
This kills the code performance as the IY is the most expensive register.
It seems to me that SDCC resolves the accesses to the globals and static like they would constantly have to be updated.
Starting with the function:
even with
we get a lot of updates of the memory locations reserved for
dxeven if the temporary register pair would be better:Explicitly using the temporary variable produces much better code:
And to confirm the initial report as soon as
--reserve-regs-iyis not specified, thecalcis even with-max-allocs-per-node2900000compiled (TD- 4.5.2 #15383) to:Last edit: Janko Stamenović 2025-10-13