]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: Remove zba check in bitwise and ashift reassociation [PR 115921]
authorXi Ruoyao <xry111@xry111.site>
Mon, 13 Jan 2025 20:11:38 +0000 (13:11 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Mon, 13 Jan 2025 20:11:38 +0000 (13:11 -0700)
commita9ebf249063d2e8f6e8813fc954276766ad3a2fe
tree7b7d0c085540f261299c00e6b02b18be39909547
parenta52812a65cc10ef604100162c7c97ad7f4b37214
RISC-V: Remove zba check in bitwise and ashift reassociation [PR 115921]

The test case

    long
    test (long x, long y)
    {
      return ((x | 0x1ff) << 3) + y;
    }

is now compiled (-O2 -march=rv64g_zba) to

    li      a4,4096
    slliw   a5,a0,3
    addi    a4,a4,-8
    or      a5,a5,a4
    addw    a0,a5,a1
    ret

Despite this check was originally intended to use zba better, now
removing it actually enables the use of zba for this test case (thanks
to late combine):

    ori    a5,a0,511
    sh3add  a0,a5,a1
    ret

Obviously, bitmanip.md does not cover
(any_or (ashift (reg) (imm123)) imm) at all, and even for and it just
seems more natural splitting to (ashift (and (reg) (imm')) (imm123))
first, then let late combine to combine the outer ashift and the plus.

I've not found any test case regressed by the removal.
And "make check-gcc RUNTESTFLAGS=riscv.exp='zba-*.c'" also reports no
failure.

gcc/ChangeLog:

PR target/115921
* config/riscv/riscv.md (<optab>_shift_reverse): Remove
check for TARGET_ZBA.

gcc/testsuite/ChangeLog:

PR target/115921
* gcc.target/riscv/zba-shNadd-08.c: New test.
gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/zba-shNadd-08.c [new file with mode: 0644]