[Patch] MOV/SHR reference optimisation (x64 only)
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 optimises 64-bit reads from memory that then discard the lower 32-bits with SHR. That is, it replaces pairs such as:
movq (%rdx),%rax
shrq $32,%rax
With:
movl 4(%rdx),$eax
Shifts greater than 32 are also optimised, with the register size changed to 32-bit and 32 subtracted from the shift amount. This may open up deeper optimisations and are smaller in code size.
Steps to reproduce:
Apply patch and confirm correct compilation.
Additional information:
A nice cascade optimisation can be seen in the System unit:
...
movq (%rcx),%rax
shrq $32,%rax
andl $-2147483648,%eax (presumably a TEST instruction appeared after this line that was removed in the post-peephole stage)
jne .Lj1562
...
Becomes:
...
je .Lj1562
# Peephole Optimization: movq (%rcx),%rax; shrq $32,%rax -> movl 4(%rcx),%eax (MovShr2Mov)
# Peephole Optimization: MovAndTest2Test done
testl $-2147483648,4(%rcx)
jne .Lj1562
...
Mantis conversion info:
- Mantis ID: 38560
- OS: Microsoft Windows
- OS Build: 10 Home
- Build: r48842
- Platform: x86_64
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 48857 (#8ffa01e9)