[Patch] x86 "OptPass1MOV" improvements - Part 2
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 introduces some deeper optimisation to MOV operations and the instructions that immediately follow them, changing registers of equal value to avoid pipeline stalls, but which also does the work of many other optimisations in OptPass1MOV (these will be factored out later).
For example, one method in the Lazarus source used to compile into the following:
pushq %rbp
movq %rcx,%rbp
movq -8(%rbp),%rax
movb $0,2080(%rax)
popq %rbp
ret
With the new optimisation, the "movq -8(%rbp),%rax" instruction becomes "movq -8(%rcx),%rax", breaking the dependency chain between it and the "movq %rcx,%rbp" instruction before it (future research may also identify the fact that %rbp is not required and so can simplify the structured exception handling for this routine).
Steps to reproduce:
Apply patch and confirm correct compilation of i386 and x86_64 builds of the compiler, as well as test runs (my own tests on i386-win32 and x86_64-win64 show no regressions).
Additional information:
Most of the optimsation code is in its own routine, named DeepMOVOpt. This is so the code can be reused later on with the deeper MOV optimisations that use GetNextInstructionUsingReg.
Some optimisations have been observed to be redundant and no longer necessary. These will be stripped out in a future patch once it is observed that they truly are redundant - these include, but are not limited to:
- MovTest/Cmp/Or/AndJxx2Test/Cmp/Or/AndJxx when using CMP
- MovTest/Cmp/Or/AndJxx2MovTest/Cmp/Or/AndJxx when using CMP
- MovMov2Mov 2
- MovMov2Mov 4
- MovMov2Mov 6c
- Mov2Nop 2 (related to MovMov2Mov 6c)
- Some MOV/MOVZX and MOV/MOVSX optimisations.
Some "MovTestCmp2MovTestCmp 1" optimisations get missed because the reference in the MOV instruction gets its register changed (thus no longer matching the reference in the CMP instruction). This will get rectified when the GetNextInstructionUsingReg optimisations are extended to use DeepMOVOpt and thus change this reference as well.
Mantis conversion info:
- Mantis ID: 36608
- OS: Microsoft Windows
- OS Build: 10 Professional
- Build: r44000
- Platform: i386 and x86_64
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 44086 (#2ea35e55)