]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: No extensions for SImode min/max against safe constant
authorPhilipp Tomsich <philipp.tomsich@vrull.eu>
Sun, 16 Oct 2022 08:51:47 +0000 (10:51 +0200)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Fri, 18 Nov 2022 20:23:41 +0000 (21:23 +0100)
commit3142265dedd84c2f3dbf824f2d1b0c182e3c8b3c
tree70cb060b825811f3b5422e2ff6906e83371f4396
parent60d2bcc55bcc0991c0e58e97edf4a69e847e82c6
RISC-V: No extensions for SImode min/max against safe constant

Optimize the common case of a SImode min/max against a constant
that is safe both for sign- and zero-extension.
E.g., consider the case
  int f(unsigned int* a)
  {
    const int C = 1000;
    return *a * 3 > C ? C : *a * 3;
  }
where the constant C will yield the same result in DImode whether
sign- or zero-extended.

This should eventually go away once the lowering to RTL smartens up
and considers the precision/signedness and the value-ranges of the
operands to MIN_EXPR and MAX_EXPR.

gcc/ChangeLog:

* config/riscv/bitmanip.md (*minmax): Additional pattern for
  min/max against constants that are extension-invariant.
* config/riscv/iterators.md (minmax_optab): Add an iterator
  that has only min and max rtl.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbb-min-max-02.c: New test.
gcc/config/riscv/bitmanip.md
gcc/config/riscv/iterators.md
gcc/testsuite/gcc.target/riscv/zbb-min-max-02.c [new file with mode: 0644]