This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Optimize add/sub with immediate
AbandonedPublic

Authored by benshi001 on Sep 25 2021, 6:09 AM.

Details

Summary

Optimize ([add|sub] r, imm) -> ([ADD|SUB] ([ADD|SUB] r, #imm0, lsl #12), imm1),
if imm == (imm0<<12)+imm1. and both imm0 and imm1 are non-zero 12-bit unsigned
integers.

Optimize ([add|sub] r, imm) -> ([SUB|ADD] ([SUB|ADD] r, #imm0, lsl #12), imm1),
if imm == -(imm0<<12)-imm1, and both imm0 and imm1 are non-zero 12-bit unsigned
integers.

Diff Detail

Event Timeline

benshi001 created this revision.Sep 25 2021, 6:09 AM
benshi001 requested review of this revision.Sep 25 2021, 6:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 25 2021, 6:09 AM
benshi001 added inline comments.Sep 25 2021, 6:10 AM
llvm/test/CodeGen/AArch64/addimm-mulimm.ll
56–58

I think this is still a win, since an extra register w9 is saved, although the total amount of instructions does not change.

benshi001 updated this revision to Diff 375077.Sep 25 2021, 7:46 PM

It seems the build failures do not related to my modification.

Similar to D109963, this may make things worse if the code is in a loop and the MOVi is loop invariant. That patch adds a new AArch64 peephole optimization pass, and this sounds like this change would fit in there nicely too.

Similar to D109963, this may make things worse if the code is in a loop and the MOVi is loop invariant. That patch adds a new AArch64 peephole optimization pass, and this sounds like this change would fit in there nicely too.

Thanks. I will fit my code to that pass after the D109963 is merged.