[Patch] Register promotion for single-field record types
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:
A developer came to me directly asking about an optimisation, and I raised it on the fpc-devel mailing list, namely the slightly sub-optimal situation where local variables of record types are always stored on the stack, never promoted to a register. While there is still some research to be done in this area of optimisation, the patch supplied will promote variables where the record type contains just a single field.
RegVar.lpr is a test program that shows the optimisation in action.
Steps to reproduce:
- Compile test program RegVar.lpr, without the patch applied, and verify that the 2nd time metric (with the "Slow" comment) runs notably slower than the other two.
- Apply patch and then compile the test program again, and this time verify that the 2nd time metric is comparable to the other two.
- Confirm that the compiler has not suffered any regressions elsewhere.
Additional information:
Special thanks to Jonas Maebe for directing me to some useful internal methods that made this optimisation remarkably simple.
The most important changes in the patch exist only in the file "compiler/symsym.pas", where only 2 lines of code are added. The other changes relate to common subexpression elimination.
Mantis conversion info:
- Mantis ID: 37343
- OS: Microsoft Windows
- OS Build: 10 Professional
- Build: r45763
- Platform: Cross-platform
- Version: 3.3.1
- Fixed in version: 3.3.1
- Monitored by: » @MageSlayer (Denis Golovan), » @sergy.larin (Sergey Larin)
- Target version: 4.0.0