RISC-V: Increase mult/div cost if not implemented in hardware.

Message ID 20180116030418.4704-1-jimw@sifive.com
State New
Headers show
Series
  • RISC-V: Increase mult/div cost if not implemented in hardware.
Related show

Commit Message

Jim Wilson Jan. 16, 2018, 3:04 a.m.
This increases the cost of multiply and divide when not present.  This makes it
more likely that a multiply by constant gets replaced by a sequence of shift
and adds which is faster than a call to a libgcc routine.  The divide cost
change doesn't do anything useful at present, but is added for consistency.

This was tested with a make check-gcc.  There were no regressions.

Committed.

Jim

	2018-01-15  Andrew Waterman  <andrew@sifive.com>
	gcc/
	* config/riscv/riscv.c (riscv_rtx_costs) <MULT>: Increase cost if
	!TARGET_MUL.
	<UDIV>: Increase cost if !TARGET_DIV.
---
 gcc/config/riscv/riscv.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

-- 
2.14.1

Patch

diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index d260c0ebae1..19a01e0825a 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -1615,6 +1615,9 @@  riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
     case MULT:
       if (float_mode_p)
 	*total = tune_info->fp_mul[mode == DFmode];
+      else if (!TARGET_MUL)
+	/* Estimate the cost of a library call.  */
+	*total = COSTS_N_INSNS (speed ? 32 : 6);
       else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
 	*total = 3 * tune_info->int_mul[0] + COSTS_N_INSNS (2);
       else if (!speed)
@@ -1635,7 +1638,10 @@  riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
 
     case UDIV:
     case UMOD:
-      if (speed)
+      if (!TARGET_DIV)
+	/* Estimate the cost of a library call.  */
+	*total = COSTS_N_INSNS (speed ? 32 : 6);
+      else if (speed)
 	*total = tune_info->int_div[mode == DImode];
       else
 	*total = COSTS_N_INSNS (1);