[Patch] x86 MOVZX/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 makes an addition to the in-depth OptPass2Movx routine so that it can accommodate CMP instructions. In other words, if there are calls to MOVZX that then manipulate the register and then use CMP to compare it to a constant, the Peephole Optimizer will attempt to convert the MOVZX instruction to a MOV instruction and decrease the size of the sub-register if the constant sizes are small enough. Generally it won't make the code any faster, but it will decrease its size in some places without penalty.
Steps to reproduce:
Apply patch and confirm correct code compilation and slight code size reduction
Additional information:
An example from sfpux80:
Before:
.seh_proc SFPUX80_$$_FLOATX80_IS_SIGNALING_NAN$FLOATX80$$BYTE
...
movzwl 8(%rsp),%eax
andl $32767,%eax
cmpl $32767,%eax
After:
.seh_proc SFPUX80_$$_FLOATX80_IS_SIGNALING_NAN$FLOATX80$$BYTE
...
# Peephole Optimization: Movzx2Mov 1a
movw 8(%rsp),%ax
andw $32767,%ax
cmpw $32767,%ax
On this sequence alone, by reducing the register size from %eax and %ax, 5 bytes are saved: one fewer byte from using MOV instead of MOVZX, and 2 bytes each for ANDW and CMPW because the constants are now 16-bit instead of 32-bit.
Mantis conversion info:
- Mantis ID: 38882
- OS: Microsoft Windows
- OS Build: 10 Home
- Build: r49349
- Platform: i386 and x86_64
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 49366 (#884d24e3)