This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add matching of codegen patterns to RISCV Bit Manipulation Zbs asm instructions
ClosedPublic

Authored by PaoloS on May 13 2020, 8:52 AM.

Details

Summary

This patch provides optimization of bit manipulation operations by enabling
the +experimental-b target feature.
It adds matching of single block patterns of instructions to specific bit-manip
instructions from the single-bit subset (zbs subextension) of the experimental
B extension of RISC-V.
It adds also the correspondent codegen tests.

This patch is based on Clifford Wolf's proposal for the bit manipulation
extension of RISCV:
https://github.com/riscv/riscv-bitmanip/blob/master/bitmanip-0.92.pdf

Diff Detail

Event Timeline

PaoloS created this revision.May 13 2020, 8:52 AM
lewis-revill added inline comments.Jul 9 2020, 7:46 AM
llvm/lib/Target/RISCV/RISCVInstrInfoB.td
673

Why does this need to be riscv_sllw as opposed to shl? Isn't the former intended for matching patterns resulting from a 32 bit operation?

PaoloS marked an inline comment as done.Jul 9 2020, 6:45 PM
PaoloS added inline comments.
llvm/lib/Target/RISCV/RISCVInstrInfoB.td
673

Indeed. That happened because some constants in the samples used to discover the patterns were set by default to 32 bit. Fixed, thank you.

PaoloS updated this revision to Diff 276892.Jul 9 2020, 6:50 PM

Added pattern-matching for sbexti, sbclrw, sbsetw, sbinvw and sbextw.
Added correspondent codegen tests.
Reorganized the tests so that both 32 and 64 bit files have both 32 and 64 bit versions of each test.
Fixed some imprecise patterns due to unnecessary constant truncations.

PaoloS added a comment.Jul 9 2020, 6:56 PM

I had to exclude the test of the pattern of sbclr_i64 on RV32 because it caused a warning of asm conflicts. Also the cross tests i64 on RV32 are quite noisy here. I'd rather keep them though as they show quite efficient results on many other instructions in other subextensions.

PaoloS updated this revision to Diff 277532.Jul 13 2020, 12:32 PM

Updated the test:

  • the tests have been updated from the top of all the sub-patches together so that they are exactly the same as they would be if updated with the whole final patch.
  • labels specific to the sub-extension have been added alongside the generic RISCVIB label (that activates all the sub-extensions) so that we can see how differently the patterns are matched with the specific subextension or with all of them together.
  • the tests will probably fail if run by checking out the commit of a subextension and if updated they'll change. These tests are designed to work with the final squashed patch.
PaoloS edited the summary of this revision. (Show Details)Jul 14 2020, 6:57 AM
This revision is now accepted and ready to land.Jul 14 2020, 8:10 AM
PaoloS marked an inline comment as done.Jul 14 2020, 10:24 AM
PaoloS updated this revision to Diff 277925.Jul 14 2020, 11:43 AM

Added comments to inefficient tests.

This revision was automatically updated to reflect the committed changes.