]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: costs: support shift-and-add in strength-reduction
authorPhilipp Tomsich <philipp.tomsich@vrull.eu>
Wed, 10 Nov 2021 16:30:20 +0000 (17:30 +0100)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Sun, 13 Nov 2022 15:38:46 +0000 (16:38 +0100)
commitf90cb39235c4971c4399c782d4d7566242b5886b
tree6b94233d93fd261fb25b1530cdc3e23fbd99c648
parent5e749ee3019d7917184af30dab8d09c933c0a4a1
RISC-V: costs: support shift-and-add in strength-reduction

The strength-reduction implementation in expmed.cc will assess the
profitability of using shift-and-add using a RTL expression that wraps
a MULT (with a power-of-2) in a PLUS.  Unless the RISC-V rtx_costs
function recognizes this as expressing a sh[123]add instruction, we
will return an inflated cost---thus defeating the optimization.

This change adds the necessary idiom recognition to provide an
accurate cost for this for of expressing sh[123]add.

Instead on expanding to
li a5,200
mulw a0,a5,a0
with this change, the expression 'a * 200' is sythesized as:
sh2add a0,a0,a0   // *5 = a + 4 * a
sh2add a0,a0,a0   // *5 = a + 4 * a
slli a0,a0,3    // *8

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_rtx_costs): Recognize shNadd,
if expressed as a plus and multiplication with a power-of-2.
Split costing for MINUS from PLUS.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zba-shNadd-07.c: New test.
gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/zba-shNadd-07.c [new file with mode: 0644]