[Patch] x86: Lea2Nop for stack pointer
Original Reporter info from Mantis: CuriousKit @CuriousKit
-
Reporter name: J. Gareth Moreton
Original Reporter info from Mantis: CuriousKit @CuriousKit
- Reporter name: J. Gareth Moreton
Description:
Occasionally, the DeepMovOpt routine produces "lea (%rsp),%rsp" instructions (or %esp for i386) because it recognises that another register, usually %rbp, is equal to the stack pointer and hasn't changed. As such, "lea (%rbp),%rsp" and hence "lea (%rsp),%rsp" is effectively a null operation because no flags are set and the stack pointer doesn't change value. However, OptPass1LEA does not touch lea instructions that set the stack pointer. This patch adds an exception to that rule, permitting the removal of "lea (%rsp),%rsp". This generally also allows the removal of the earlier "mov %rsp,%rbp" (via Mov2Nop 3b) if %rbp is no longer used.
Steps to reproduce:
Apply patch and confirm correct compilation.
Additional information:
The RTL only shows one case of this optimisation in the system unit for x86_64-win64, but there are many cases of it being applied in the compiler itself.
Mantis conversion info:
- Mantis ID: 39225
- OS: Microsoft Windows
- OS Build: 10 Home
- Build: r49608
- Platform: i386 and x86_64
- Version: 3.3.1
- Fixed in revision: 49612 (#2629bd7b)