]> git.ipfire.org Git - thirdparty/gcc.git/commit
[PATCH][PR target/121778] RISC-V: Improve rotation detection for RISC-V
authorDusan Stojkovic <Dusan.Stojkovic@rt-rk.com>
Wed, 24 Sep 2025 21:11:58 +0000 (15:11 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Wed, 24 Sep 2025 21:13:01 +0000 (15:13 -0600)
commitd53f7ad85e8aefc6f0cdc0dd2f541db59d1a0cd2
tree5aaf3960a724bb27bfa79a6531ed77ccc9270341
parentdfbce1feae0a88dd94bdba1adc5040e4a86c6219
[PATCH][PR target/121778] RISC-V: Improve rotation detection for RISC-V

This patch splits the canonical sign-bit checking idiom
into a 2-insn sequence when Zbb is available. Combine often normalizes
(xor (lshr A, (W - 1)) 1) to (ge A, 0). For width W = bitsize (mode), the
identity:

(a << 1) | (a >= 0)  ==  (a << 1) | ((a >> (W - 1)) ^ 1)  ==  ROL1 (a) ^ 1

lets us split:

(ior:X (ashift:X A 1) (ge:X A 0))

into:
  →  rotatert:X A, (W-1)
  →  xor:X        A, 1

PR target/121778

gcc/ChangeLog:

* config/riscv/riscv.md: Add define_split pattern.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr121778-1.c: New test.
* gcc.target/riscv/pr121778-2.c: New test.
gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/pr121778-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/pr121778-2.c [new file with mode: 0644]