This is an archive of the discontinued LLVM Phabricator instance.

[LoongArch] Add codegen support for bitreverse
ClosedPublic

Authored by xen0n on Aug 7 2022, 11:22 PM.

Diff Detail

Event Timeline

xen0n created this revision.Aug 7 2022, 11:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2022, 11:22 PM
xen0n requested review of this revision.Aug 7 2022, 11:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2022, 11:22 PM
SixWeining added inline comments.Aug 8 2022, 3:03 AM
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
84

How about leave it to legal and use bitrev.4b+srli.w/d. I'm not sure which is fast and better.

llvm/test/CodeGen/LoongArch/bitreverse.ll
3

Nit: had better use --.

SixWeining added inline comments.Aug 8 2022, 4:04 AM
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
84

Sorry, I mean bitrev.w/d+srli.w/d.

xen0n updated this revision to Diff 451181.Aug 9 2022, 9:08 AM

Prefer simple shifts over byteswapping for bitreverse.i16, per @SixWeining's suggestion

xen0n updated this revision to Diff 451190.Aug 9 2022, 10:02 AM
xen0n marked 2 inline comments as done.

Implement bswap+bitreverse combining.

xen0n edited the summary of this revision. (Show Details)Aug 9 2022, 10:03 AM
xen0n updated this revision to Diff 451192.Aug 9 2022, 10:08 AM

Use double dashes for the mtriple option of llc.

xen0n marked an inline comment as done.Aug 9 2022, 10:11 AM
xen0n updated this revision to Diff 451196.Aug 9 2022, 10:13 AM

micro-manipulation of comment wording

xen0n updated this revision to Diff 451197.Aug 9 2022, 10:15 AM

whoops forgot this line, change to use the exact same wording as in the .td file

xen0n added a comment.Aug 9 2022, 11:05 AM

Oh well. BITREV_I8 and BITREV_4B are actually the same. But it's 2AM now so let me finish tweaking this later.

xen0n updated this revision to Diff 451335.Aug 9 2022, 7:33 PM

remove redundant code

LGTM except some nits.

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
88

Legal is default. So we can omit it. And then we can omit the braces after if and before else since the body is simple. See the coding standard.

Same as below.

827

Indent.

832

Inline one-time used variable, per @MaskRay's suggestions previously.

xen0n marked an inline comment as done.Aug 10 2022, 12:41 AM
xen0n added inline comments.
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
88

Unfortunately this seems not to be the case. If I remove both Legal setting then the operation gets expanded instead. See lib/CodeGen/TargetLoweringBase.cpp:839, it defaults to Expand.

xen0n updated this revision to Diff 451370.Aug 10 2022, 12:46 AM
xen0n marked an inline comment as done.

address @SixWeining's review comments, also use consistent signature for performBITREV_WCombine

xen0n marked 2 inline comments as done.Aug 10 2022, 12:46 AM
SixWeining accepted this revision.Aug 10 2022, 12:59 AM

LGTM. Thanks!

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
88

Oh. My bad. :)

This revision is now accepted and ready to land.Aug 10 2022, 12:59 AM
This revision was automatically updated to reflect the committed changes.