]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/config/riscv/riscv-protos.h
RISC-V: Add divmod expansion support
authorMatevos Mehrabyan <matevosmehrabyan@gmail.com>
Fri, 28 Apr 2023 20:01:30 +0000 (14:01 -0600)
committerJeff Law <jlaw@ventanamicro>
Fri, 28 Apr 2023 20:03:32 +0000 (14:03 -0600)
commit065be0ffbcd676b635d492f4679e635b6ece4fe4
tree0a3f0fc0c100f4fec7f10335c0cc42cc54a56cdf
parentd9df45a66b2c8f543106be0a2387bbe6195b00a6
RISC-V: Add divmod expansion support

Hi all,
If we have division and remainder calculations with the same operands:

  a = b / c;
  d = b % c;

We can replace the calculation of remainder with multiplication +
subtraction, using the result from the previous division:

  a = b / c;
  d = a * c;
  d = b - d;

Which will be faster.
Currently, it isn't done for RISC-V.

I've added an expander for DIVMOD which replaces 'rem' with 'mul + sub'.

Best regards,
Matevos.

gcc/ChangeLog:

* config/riscv/iterators.md (only_div, paired_mod): New iterators.
(u): Add div/udiv cases.
* config/riscv/riscv-protos.h (riscv_use_divmod_expander): Prototype.
* config/riscv/riscv.cc (struct riscv_tune_param): Add field for
divmod expansion.
(rocket_tune_info, sifive_7_tune_info): Initialize new field.
(thead_c906_tune_info): Likewise.
(optimize_size_tune_info): Likewise.
(riscv_use_divmod_expander): New function.
* config/riscv/riscv.md (<u>divmod<mode>4): New expander.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/divmod-1.c: New testcase.
* gcc.target/riscv/divmod-2.c: New testcase.
gcc/config/riscv/iterators.md
gcc/config/riscv/riscv-protos.h
gcc/config/riscv/riscv.cc
gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/divmod-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/divmod-2.c [new file with mode: 0644]