[Patch] Peephole Optimizer pass reduction
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 aims to reduce the number of passes performed by the Peephole Optimizer without harming the quality of the code under -O2 and above. The modified routines are platform-agnostic and should apply to all platforms where the routines have not been overridden.
Most specifically, the mandatory second execution of pass 1 has been removed.
See Additional Information for specific notes.
Steps to reproduce:
Apply patch and confirm successful compilation and identical binary output under -O2 and above.
Additional information:
- The mandatory second run of pass 1 has been removed.
- -O1 will now perform slightly worse as only a single iteration of pass 1 is performed - this is deemed acceptable from past conversations and the fact that -O1 is generally only done for quick debugging.
- -O2 will perform up to 2 iterations of pass 1, but will drop out early if no changes were made in the first pass (i.e. none of the individual optimisations setting Result to True). Output should be the same as before.
- -O3 will perform up to 5 iterations of pass 1, and -O4 will perform up to 8, although it should never take that many... the finite limit is mostly a safeguard against a faulty optimisation that would otherwise cause an infinite loop. These numbers were chosen because, originally, Pass 1 has an upper limit of 4 iterations to protect against said faulty optimisations, and the mandatory second run would increase this to at least 5, or 8 if there was indeed a faulty optimisation (two runs of 4 iterations each).
Successful test criteria:
- Successful building of the compiler, RTL and no regressions in tests.
- -O2 shows no difference in the disassembly. Any differences should be indictive of an individual optimisation not setting Result to True when it should have done.
- Compile times should be generally slightly less than before, and almost equal when done under -O2 or with optimisations turned off.
Mantis conversion info:
- Mantis ID: 37959
- OS: Microsoft Windows
- OS Build: 10 Home
- Build: r47137
- Platform: Cross-platform
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 47146 (#91a62232)
- Monitored by: » @MageSlayer (Denis Golovan)