RISC-V: Split slli+sh[123]add.uw opportunities to avoid zext.w
authorPhilipp Tomsich <philipp.tomsich@vrull.eu>
Wed, 11 May 2022 10:12:57 +0000 (12:12 +0200)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Tue, 14 Jun 2022 11:37:51 +0000 (13:37 +0200)
commit0247ad3e0f4a574273b42344fbaa9346599948f9
treebb8248fe9dfa6c982c32b9a1f321f42157cf63a1
parent4bf0dcb0492c40be7e0603b13a8b5949609388dd
RISC-V: Split slli+sh[123]add.uw opportunities to avoid zext.w

When encountering a prescaled (biased) value as a candidate for
sh[123]add.uw, the combine pass will present this as shifted by the
aggregate amount (prescale + shift-amount) with an appropriately
adjusted mask constant that has fewer than 32 bits set.

E.g., here's the failing expression seen in combine for a prescale of
1 and a shift of 2 (note how 0x3fffffff8 >> 3 is 0x7fffffff).
  Trying 7, 8 -> 10:
      7: r78:SI=r81:DI#0<<0x1
        REG_DEAD r81:DI
      8: r79:DI=zero_extend(r78:SI)
        REG_DEAD r78:SI
     10: r80:DI=r79:DI<<0x2+r82:DI
        REG_DEAD r79:DI
        REG_DEAD r82:DI
  Failed to match this instruction:
  (set (reg:DI 80 [ cD.1491 ])
      (plus:DI (and:DI (ashift:DI (reg:DI 81)
                       (const_int 3 [0x3]))
               (const_int 17179869176 [0x3fffffff8]))
          (reg:DI 82)))

To address this, we introduce a splitter handling these cases.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Co-developed-by: Manolis Tsamis <manolis.tsamis@vrull.eu>
gcc/ChangeLog:

* config/riscv/bitmanip.md: Add split to handle opportunities
for slli + sh[123]add.uw

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zba-shadd.c: New test.
gcc/config/riscv/bitmanip.md
gcc/testsuite/gcc.target/riscv/zba-shadd.c [new file with mode: 0644]