[Patch] CMP chain shortcutting
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:
In a similar vein to #38908 (closed), this optimisation looks for CMP / Jcc pairs that branch to an identical CMP instruction followed by another conditional jump - in this case, as long as the first jump's condition is a subset of (or is equal to) the second jump's condition, the destination in the first jump is changed to that of the second one.
The second optimisation... if CMP/Jcc/CMP is found and the two CMPs are identical, the second CMP is removed since the flags won't change.
Steps to reproduce:
Apply patch and confirm correct compilation.
Additional information:
Example of first optimisation in Sysutils.s:
Before:
...
.Lj1564:
cmpq $0,(%rbx)
je .Lj1562
movq (%rbx),%rdx
leaq -16(%rbp),%rcx
call SYSUTILS_$$_INCLUDETRAILINGPATHDELIMITER$UNICODESTRING$$UNICODESTRING
movq -16(%rbp),%rdx
movq %rbx,%rcx
movq %rsi,%r8
call fpc_unicodestr_concat
.Lj1562:
cmpq $0,(%rbx)
je .Lj1553
...
After:
...
.Lj1564:
cmpq $0,(%rbx)
# Peephole Optimization: CMP/Jcc/@Lbl/CMP/Jcc -> CMP/Jcc, redirecting first jump
je .Lj1553 ; <-- Destination label changed
movq (%rbx),%rdx
leaq -16(%rbp),%rcx
call SYSUTILS_$$_INCLUDETRAILINGPATHDELIMITER$UNICODESTRING$$UNICODESTRING
movq -16(%rbp),%rdx
movq %rbx,%rcx
movq %rsi,%r8
call fpc_unicodestr_concat
cmpq $0,(%rbx) ; <-- .Lj1562 became a dead label
je .Lj1553
...
Mantis conversion info:
- Mantis ID: 39141
- OS: Microsoft Windows
- OS Build: 10 Home
- Build: r49576
- Platform: i386 and x86_64
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 49592 (#d16160be)