This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add support for BSWAP and BITREVERSE for RVP
Needs ReviewPublic

Authored by Jim on Jun 4 2021, 5:11 AM.

Details

Summary

Use swap8, swap16 and pkbt32 to swap bytes for XLenVT and
customized lower BITREVERSE to bitrevi.

Diff Detail

Event Timeline

Jim created this revision.Jun 4 2021, 5:11 AM
Jim requested review of this revision.Jun 4 2021, 5:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2021, 5:11 AM
jrtc27 added inline comments.Jun 4 2021, 5:18 AM
llvm/test/CodeGen/RISCV/rvp/bswap.ll
21–24 ↗(On Diff #349828)

This is not a code size win. This has also introduced more instruction dependencies; previously 1 and 2 were independent, as were 1 and 3, but now every instruction is dependent on the previous, forming a slow chain that will hurt out-of-order cores, or simple in-order cores that can't execute back-to-back P instructions with forwarding.

craig.topper added inline comments.Jun 4 2021, 4:02 PM
llvm/lib/Target/RISCV/RISCVInstrInfoP.td
1292

What if Zbb is enabled. Who gets priority?

llvm/test/CodeGen/RISCV/rvp/bswap.ll
21–24 ↗(On Diff #349828)

You probably want to catch i8/i16 on RV32/RV64 and i32 on RV64 in ReplaceNodeResults and map them to the minimum swap instruction you need before they get promoted.

Jim updated this revision to Diff 352120.Jun 15 2021, 6:28 AM

Merge https://reviews.llvm.org/D103691 into this patch.
Add the codegen of RVB for testcases.

Jim retitled this revision from [RISCV] Add support for BSWAP for RVP to [RISCV] Add support for BSWAP and BITREVERSE for RVP.Jun 15 2021, 6:29 AM
Jim edited the summary of this revision. (Show Details)
Jim updated this revision to Diff 352122.Jun 15 2021, 6:33 AM

clang-foramt

Jim updated this revision to Diff 352124.Jun 15 2021, 6:35 AM

format td file.

Jim added inline comments.Jun 15 2021, 6:41 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
5033

catch i8/i16 on RV32/RV64 and i32 on RV64

6330

I have the concern about correctness here.

llvm/lib/Target/RISCV/RISCVInstrInfoP.td
1292

Zbb would be first. Zbb only emit one grev instructions. That is better I think.