[Bug target/115921] Missed optimization: and->ashift might be cheaper than ashift->and on typical RISC targets
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jan 13 20:12:15 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115921
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <law@gcc.gnu.org>:
https://gcc.gnu.org/g:a9ebf249063d2e8f6e8813fc954276766ad3a2fe
commit r15-6877-ga9ebf249063d2e8f6e8813fc954276766ad3a2fe
Author: Xi Ruoyao <xry111@xry111.site>
Date: Mon Jan 13 13:11:38 2025 -0700
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.
More information about the Gcc-bugs
mailing list