[Patch] TEST 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:
Occasionally, you get assembly language where "test %reg,%reg" is called, followed by a conditional branch, only at the destination label, the same register is tested again with a branch that is often the exact same condition. This patch provides an optimisation that shortcuts such checks so the control flow jumps to the last label in the chain.
Steps to reproduce:
Apply patch and confirm correct compilation.
Additional information:
It can couple quite well with #38907 (closed) and other optimisations if the intermediate label becomes dead as a result - for example, in SysUtils before:
movq (%rdi),%rax
testq %rax,%rax
je .Lj6927
movq -8(%rax),%rax
.Lj6927:
testq %rax,%rax
je .Lj6929
After:
movq (%rdi),%rax
testq %rax,%rax <-- (#38907 doesn't get applied here because %rax is used in the reference below)
# Peephole Optimization: TEST/Jcc/Lbl/TEST/Jcc -> TEST/Jcc, redirecting first jump
je .Lj6929
# Peephole Optimization: MOV/CMP -> CMP (memory check)
cmpq $0,-8(%rax)
je .Lj6929
Mantis conversion info:
- Mantis ID: 38908
- 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: 49385 (#578424cf)