[Patch] Memory CMP optimisation
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:
This patch looks for combinations where a MOV instruction transfers data from memory into a register, and then immediately compares that register with CMP or TEST, simplifying it into just a CMP instruction that tests against the memory directly if the register in question is not used afterwards.
Steps to reproduce:
Apply patch and confirm correct compilation with minor speed boost.
Additional information:
For a simple example (taken from SysUtils):
movl 32(%rsp),%eax
testl %eax,%eax
Becomes:
cmpl $0,32(%rsp)
----
Assemblers seem to struggle if the reference in a TEST or CMP instruction is an absolute address (such as a global variable under i386), represented as "refaddr = addr_full" internally. As such, only references of type "addr_no" (registers and offsets only), "addr_pic" (using %rip under x86_64) and "addr_pic_no_got" are optimised.
Mantis conversion info:
- Mantis ID: 38907
- OS: Microsoft Windows
- OS Build: 10 Home
- Build: r49374
- Platform: i386 and x86_64
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 49382 (#6f482952)