View Revisions: Issue #38343

Summary 0038343: [Patch] OptPass2Jcc Refactor
Revision 2021-01-11 06:09 by J. Gareth Moreton
Additional Information List of changes:

- All relevant optimisations now within an if-block that cheks that GetNextInstruction(p, hp1) returns True and hp1 is an instruction, thus removing the need to call them for each optimisation.
- The JccAdd/Inc/Dec2CmcAdc/Sbb, JccAdd/Inc/Dec2Adc/Sbb and JccAdd2SetccAdd optimisations are now more efficient in how they check the relevant instructions (namely it doesn't check the operand types and values multiple times).
- On i386, and additionally i8086 (although i8086 doesn't use Pass 2 yet), JccAdd2SetccAdd checks to see if the register is EAX, EBX, ECX or EDX first, since this is a cheaper check and avoids calling GetUsedRegs and paramanager.get_volatile_registers_int for registers that can't have their lowest byte set (ESI, EDI, ESP, EBP).
- JccAdd2SetccAdd now returns True and exits, since p changes from Jcc to SETcc.
- The JccMov2CMov removes an initial call to GetNextInstruction because it already knows what hp1 is.

Possible future improvements:
- A separate utility method for getting a free register, possibly allowing for smarter behaviour in order to permit more optimisations (e.g. allowing non-volatile registers that have been preserved on the stack in the function prologue).
- Improving the cross-platform jump optimisations to recognise RET operations and equivalent on other platforms, seeing them effectively as unconditional jumps. This would allow the removal of the JccJmpRet2J!ccRet optimisation which otherwise follows very simialr principles to the cross-platform jump optimisations (the code path for this optimisation also seems to be very rarely taken).

Miscellaneous:
- Stack size for OptPass2Jcc increases by 4 bytes on i386-win32 and x86_64-win64, but overall code base is smaller.
Revision 2021-01-11 06:07 by J. Gareth Moreton
Additional Information List of changes:

- All relevant optimisations now within an if-block that cheks that GetNextInstruction(p, hp1) returns True and hp1 is an instruction, thus removing the need to call them for each optimisation.
- The JccAdd/Inc/Dec2CmcAdc/Sbb, JccAdd/Inc/Dec2Adc/Sbb and JccAdd2SetccAdd optimisations are now more efficient in how they check the relevant instructions (namely it doesn't check the operand types and values multiple times).
- On i386, and additionally i8086 (although i8086 doesn't use Pass 2 yet), JccAdd2SetccAdd checks to see if the register is EAX, EBX, ECX or EDX first, since this is a cheaper check and avoids calling GetUsedRegs and paramanager.get_volatile_registers_int for registers that can't have their lowest byte set (ESI, EDI, ESP, EBP).
- JccAdd2SetccAdd now returns True and exits, since p changes from Jcc to SETcc.
- The JccMov2CMov removes an initial call to GetNextInstruction because it already knows what hp1 is.

Possible future improvements:
- A separate utility method for getting a free register, possibly allowing for smarter behaviour in order to permit more optimisations (e.g. allowing non-volatile registers that have been preserved on the stack in the function prologue).
- Improving the cross-platform jump optimisations to recognise RET operations and equivalent on other platforms, seeing them effectively as unconditional jumps. This would allow the removal of the JccJmpRet2J!ccRet optimisation which otherwise follows very simialr principles to the cross-platform jump optimisations (the code path for this optimisation also seems to be very rarely taken).

Miscellaneous:
- Stack size of OptPass2Jcc increases by 4 bytes, but overall code base is smaller.