https://gcc.gnu.org/g:27a363607ed79235c112c044daa8501e9d1b4d6d
commit r17-6482-g27a363607ed79235c112c044daa8501e9d1b4d6d Author: Jiawei <[email protected]> Date: Thu Nov 19 20:56:23 2026 +0800 RISC-V: Use rori and xori for a complemented sign bit with Zbkb The splitter for a one-bit left rotation with the incoming bit inverted emits rori and xori. Enable it for Zbkb, which also provides rori. gcc/ChangeLog: * config/riscv/riscv.md: Enable the rotate-and-invert splitter for Zbkb. gcc/testsuite/ChangeLog: * gcc.target/riscv/pr121778-3.c: New test. Diff: --- gcc/config/riscv/riscv.md | 2 +- gcc/testsuite/gcc.target/riscv/pr121778-3.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 6588a1c4ffa7..22579ad1ef4c 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -4970,7 +4970,7 @@ (ashift:X (match_operand:X 1 "register_operand") (const_int 1)) (ge:X (match_dup 1) (const_int 0))))] - "TARGET_ZBB" + "TARGET_ZBB || TARGET_ZBKB" [(set (match_dup 0) (rotatert:X (match_dup 1) (match_operand 2 "const_int_operand"))) (set (match_dup 0) diff --git a/gcc/testsuite/gcc.target/riscv/pr121778-3.c b/gcc/testsuite/gcc.target/riscv/pr121778-3.c new file mode 100644 index 000000000000..de407a57a00d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr121778-3.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv64gc_zbkb -mabi=lp64" { target rv64 } } */ +/* { dg-options "-O2 -march=rv32gc_zbkb -mabi=ilp32" { target rv32 } } */ + +unsigned long +foo (unsigned long x) +{ + return (x << 1) | ((long) x >= 0); +} + +/* { dg-final { scan-assembler {\mrori\M} } } */ +/* { dg-final { scan-assembler {\mxori\M} } } */
