Fix PR 106601: __builtin_bswap16 code gen could be improved with ZBB enabled
authorAndrew Pinski <apinski@marvell.com>
Fri, 19 Aug 2022 17:46:40 +0000 (17:46 +0000)
committerAndrew Pinski <apinski@marvell.com>
Wed, 24 Aug 2022 18:30:44 +0000 (11:30 -0700)
commite5e6983c3da53729e58a32af1d531ea74b3dbf5d
tree1de40f51a76673e5c4953b1a48e4a9e6bda3bd00
parentcb2daf5acce003300ee948a89860c0d13ebcae79
Fix PR 106601: __builtin_bswap16 code gen could be improved with ZBB enabled

The default expansion for bswap16 is two extractions (shift/and)
followed by an insertation (ior) and then a zero extend. This can be improved
with ZBB enabled to just full byteswap followed by a (logical) shift right.
This patch adds a new pattern for this which does that.

OK? Built and tested on riscv32-linux-gnu and riscv64-linux-gnu.

gcc/ChangeLog:

PR target/106601
* config/riscv/bitmanip.md (bswaphi2): New pattern.

gcc/testsuite/ChangeLog:

PR target/106601
* gcc.target/riscv/zbb_32_bswap-2.c: New test.
* gcc.target/riscv/zbb_bswap-2.c: New test.
gcc/config/riscv/bitmanip.md
gcc/testsuite/gcc.target/riscv/zbb_32_bswap-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/zbb_bswap-2.c [new file with mode: 0644]