On 11/16/26 5:22 AM, Jiawei wrote:
Use bset, binv and bclr when a zero-extended word-sized bit mask
is combined with a 64-bit value. Handle the complemented mask form
produced by combine with Zbs alone, and retain the count mask.
The targeted riscv.exp test passes on RV64. C selftests and QEMU
checks on RV32 and RV64 also passed.
At -O2 with RV64 Zbb+Zbs, the scalar-call microbenchmarks, including
call overhead, retire 7.68% fewer instructions in gem5 and about 7.69%
fewer on K1. K1 cycles decrease by 27.05-27.14% in testcases.
gcc/ChangeLog:
* config/riscv/bitmanip.md (*<bit_optab>di_zext_si): New pattern.
(*bclrdi_zext_si): Ditto.
Add a split for the complemented word-mask form.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/zbs-word-mask.c: New test.
Fairly surprised to see the zero-extend forms showing up in practice,
but if they are, then this obviously great.
The zero-extend wrapping defines away a class of concerns, which is
obviously good.
The next area to worry about would be junk bits in the shift count. The
first two patterns don't change the operation's mode and are thus
trivially OK from that standpoint. However, I'm concerned about the
final pattern. If we change the mode of the operation, that changes
what bits GCC thinks are significant in the shift count and can possibly
lead to incorrect code generation.
Refer to this change:
commit 05d75c5bfcf923bc0258b79a08c5861590c5a2b9
Author: Jeff Law<[email protected]>
Date: Mon May 5 17:14:29 2025 -0600
[RISC-V][PR target/119971] Avoid losing shift count masking
I'm generalizing what we found with that bug to your case. If you can
convince me you case is safe, then we can keep it.
So I'll ack the first two patterns as-is right now. You should go ahead
and push them when it's convenient for you. The final pattern needs
further discussion.
Jeff