This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Lower multiplication by a constant int to shl+sub+shl
ClosedPublic

Authored by Allen on Sep 27 2022, 12:26 AM.

Details

Summary

Decompose the const 14 can be separated from D132322
Change the costmodel to lower a = b * C where C = 2^n - 2^m to

lsl     w8, w0, n
sub     w0, w8, w0, lsl m

Diff Detail

Event Timeline

Allen created this revision.Sep 27 2022, 12:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 12:26 AM
Allen requested review of this revision.Sep 27 2022, 12:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 12:26 AM
efriedma added inline comments.Sep 27 2022, 2:28 PM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
14849

The use of all these booleans makes the actual code generation difficult to understand.

Maybe we can simplify with a few lambdas? Name them Shl, Add, Sub, Negate. Then for each case, write out the operations explicitly. For example, in this case, instead of setting AddSubOpc and Sub2Shift, you can write return Sub(Shl(N0, ShiftAmt), Shl(N0, TrailingZeroes)).

Allen updated this revision to Diff 463507.Sep 28 2022, 5:09 AM

address commit, using Lambda

efriedma added inline comments.Sep 28 2022, 10:45 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
14832

Since the shift amount is always a constant here, might as well put the call to DAG.getConstant() inside the Shl lambda.

LLVM coding guidelines say you should avoid using "auto" when it's easy to spell out the type.

Allen updated this revision to Diff 463737.Sep 28 2022, 6:28 PM

address comment

Allen marked 2 inline comments as done.Sep 28 2022, 6:29 PM
Allen added inline comments.
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
14832

Done, thanks for your suggestion

This revision is now accepted and ready to land.Sep 29 2022, 9:55 AM
This revision was automatically updated to reflect the committed changes.
Allen marked an inline comment as done.