Skip to content
Snippets Groups Projects
Commit 065be0ff authored by Matevos Mehrabyan's avatar Matevos Mehrabyan Committed by Jeff Law
Browse files

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.
parent d9df45a6
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment