gcc-ia16
gcc-ia16 copied to clipboard
Missed optimisation: lea that evaluates to same offset as sp
Something I noticed in https://github.com/FDOS/kernel/pull/81#issuecomment-1146652810 it uses lea ax, [bp - 18h] just after a sub sp that computes the exact same address.
7C80:2E7E 55 push bp
7C80:2E7F 89E5 mov bp, sp
7C80:2E81 83EC18 sub sp, +18
7C80:2E84 8D46E8 lea ax, [bp-18]
7C80:2E87 50 push ax
7C80:2E88 B81200 mov ax, 0012
7C80:2E8B 50 push ax
7C80:2E8C E844D3 call 01D3
-
7C80:2E8F 8B46E8 mov ax, [bp-18]
7C80:2E92 89EC mov sp, bp
7C80:2E94 5D pop bp
7C80:2E95 C3 retn
NB the optimisation allowed here is to use mov ax, sp. The choice to use push sp would not be portable as its behaviour differs depending on the CPU, so is not an alternative here.