[Patch] Processor-aware MOVZX optimisation cleanup
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 resolves some issues where MOVZX and MOV/AND optimisations were 'fighting' each other. Now, if the compiler is optimising for the Pentium II or later (always the case with x86-64) or for size, it will favour MOVZX operations (under i8086, it will check to see if the CPU is at least an 80386, the processor that the instruction was introduced on); otherwise, it will favour the MOV/AND optimisations.
In cases where a register is zero-extended to itself, when optimising for size, it will favour using AND if the register in question is EAX, since this compiles into fewer bytes of machine code. This optimisation is not favoured for speed because it risks a partial write penalty.
Steps to reproduce:
Apply patch and confirm correct compilation and better use of MOVZX (or lack of, depending on the optimisation settings).
Additional information:
This patch was tested as part of a mass-patch regression test alongside #36669 (closed), #36670 (closed), #36675 (closed) and #36680 (closed) and passed successfully, using the options "-O4 -CpCOREAVX2" when building the compiler for i386-win32 and x86_64-win64.
Additionally, optimisations "var16", "var17" and "var18" were removed because there aren't any 64-bit versions of MOVZX (the 32-bit versions do this implicitly), so these optimisations should logically never execute. If it turns out they were executed, Internal Error 2017050704 will now be raised, because the compiler should not be generating such 64-bit MOVZX instructions.
Mantis conversion info:
- Mantis ID: 36687
- OS: Microsoft Windows
- OS Build: 10 Professional
- Build: r44140
- Platform: i386 and x86_64
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 44233 (#4dff373f)