This is an archive of the discontinued LLVM Phabricator instance.

[X86FixupLEAs] Try again to transform the sequence LEA/SUB to SUB/SUB
ClosedPublic

Authored by Carrot on Jun 21 2021, 8:52 PM.

Details

Summary

This patch transforms the sequence

    lea (reg1, reg2), reg3
    sub reg3, reg4

to two sub instructions

    sub reg1, reg4
    sub reg2, reg4

Similar optimization can also be applied to LEA/ADD sequence.
The modifications to TwoAddressInstructionPass is to ensure the operands of ADD instruction has expected order (the dest register of LEA should be src register of ADD).

Now it handles the killed operands between LEA/SUB instructions, so it can fix the verification failure when compiling @fhahn's code (test10).

Diff Detail

Event Timeline

Carrot created this revision.Jun 21 2021, 8:52 PM
Carrot requested review of this revision.Jun 21 2021, 8:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2021, 8:52 PM

I can't see anything wrong, but we've been burnt with previous iterations of this patch already. Sorry for being a little hesitant....

Maybe you could try a bootstrap stage2 build of clang with a clang built with this patch - and see if it passes?

I successfully bootstrapped a stage2 clang, also I tested stage2-check-all without regression.

RKSimon accepted this revision.Jul 15 2021, 1:03 AM

OK thanks for that. LGTM

This revision is now accepted and ready to land.Jul 15 2021, 1:03 AM