This is an archive of the discontinued LLVM Phabricator instance.

[LoongArch] Optimize multiplication with immediates
ClosedPublic

Authored by benshi001 on Apr 2 2023, 1:29 AM.

Details

Summary

Optimize 'x * c' to (ALSL x, (SLLI x, i0), i1) in which
c = (1 << i0) | (1 << i1).

Diff Detail

Event Timeline

benshi001 created this revision.Apr 2 2023, 1:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2023, 1:29 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
benshi001 requested review of this revision.Apr 2 2023, 1:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2023, 1:29 AM
xen0n added inline comments.Apr 2 2023, 1:39 AM
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
3143

Do you mean Imm - 8 and Imm - 16 instead?

benshi001 updated this revision to Diff 510324.Apr 2 2023, 1:51 AM
benshi001 marked an inline comment as done.
benshi001 added inline comments.
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
3143

Yes. Sorry for such a mistake. Has fixed.

benshi001 marked an inline comment as done.Apr 2 2023, 1:52 AM
benshi001 added inline comments.Apr 2 2023, 1:59 AM
llvm/test/CodeGen/LoongArch/ir-instruction/mul.ll
1166

This is not optimized due to the immiedate is used twice, by mul.w and mulh.w.

xen0n added inline comments.Apr 2 2023, 6:02 PM
llvm/test/CodeGen/LoongArch/ir-instruction/mul.ll
1038–1041

Kind of interesting why this didn't get optimized into the same form as LA32, but there may be a deeper reason. I don't currently have time to look into this though.

benshi001 added inline comments.Apr 2 2023, 7:04 PM
llvm/test/CodeGen/LoongArch/ir-instruction/mul.ll
1038–1041

I will take a look later, however this is still a win, since total 4 instructions are reduced to 3 ones.

benshi001 added inline comments.Apr 2 2023, 7:05 PM
llvm/test/CodeGen/LoongArch/ir-instruction/mul.ll
1038–1041

Maybe we can accept current form, and I will submit another patch for this further optimization.

xen0n accepted this revision.Apr 2 2023, 7:11 PM
xen0n added inline comments.
llvm/test/CodeGen/LoongArch/ir-instruction/mul.ll
1038–1041

Fine with me, thanks!

This revision is now accepted and ready to land.Apr 2 2023, 7:11 PM
SixWeining accepted this revision.Apr 2 2023, 7:19 PM

LGTM. Thanks.

benshi001 updated this revision to Diff 510379.Apr 2 2023, 7:26 PM
This revision was automatically updated to reflect the committed changes.
benshi001 added inline comments.Apr 2 2023, 10:21 PM
llvm/test/CodeGen/LoongArch/ir-instruction/mul.ll
1038–1041

I have fixed that issue in https://reviews.llvm.org/D147423 .

benshi001 marked an inline comment as done.Apr 2 2023, 10:22 PM