On Wed, 2018-02-14 at 01:06 +0900, Oleg Endo wrote:
>
> Do you happen to have any other numbers on the resulting code
> size/speed? Looking at the new costs that the patch introduces, I'd
> expect there to be some more changes than just the 1/x...
>
I've checked your proposed patch with the CSiBE set for code size
changes.
With your patch, the code size of the whole set:
sum: 2806044 -> 2801346 -4698 / -0.167424 %
Taking out this piece
case IF_THEN_ELSE:
*total = COSTS_N_INSNS (3);
return true;
from the rx_rtx_costs results in:
sum: 2806044 -> 2801099 -4945 / -0.176227 %
Taking out another piece
if (GET_CODE (XEXP (x, 0)) == MEM
|| GET_CODE (XEXP (x, 1)) == MEM)
*total = COSTS_N_INSNS (3);
else
results in:
sum: 2806044 -> 2800315 -5729 / -0.204166 %
So I'd like to propose the attached patch instead, as it eliminates 1
KByte of code more from the whole set.
Just in case, I'm testing it now with
"make -k check" on rx-sim for c and c++
OK for trunk if it passes?
Cheers,
Oleg
gcc/ChangeLog:
* config/rx/rx.c (rx_rtx_costs): New function.
(TARGET_RTX_COSTS): Override to use rx_rtx_costs.
Index: gcc/config/rx/rx.c
===================================================================
--- gcc/config/rx/rx.c (revision 257655)
+++ gcc/config/rx/rx.c (working copy)
@@ -2976,6 +2976,62 @@
}
static bool
+rx_rtx_costs (rtx x, machine_mode mode, int outer_code ATTRIBUTE_UNUSED,
+ int opno ATTRIBUTE_UNUSED, int* total, bool speed)
+{
+ if (x == const0_rtx)
+ {
+ *total = 0;
+ return true;
+ }
+
+ switch (GET_CODE (x))
+ {
+ case MULT:
+ if (mode == DImode)
+ {
+ *total = COSTS_N_INSNS (2);
+ return true;
+ }
+ /* fall through */
+
+ case PLUS:
+ case MINUS:
+ case AND:
+ case COMPARE:
+ case IOR:
+ case XOR:
+ *total = COSTS_N_INSNS (1);
+ return true;
+
+ case DIV:
+ if (speed)
+ /* This is the worst case for a division. Pessimize divisions when
+ not optimizing for size and allow reciprocal optimizations which
+ produce bigger code. */
+ *total = COSTS_N_INSNS (20);
+ else
+ *total = COSTS_N_INSNS (3);
+ return true;
+
+ case UDIV:
+ if (speed)
+ /* This is the worst case for a division. Pessimize divisions when
+ not optimizing for size and allow reciprocal optimizations which
+ produce bigger code. */
+ *total = COSTS_N_INSNS (18);
+ else
+ *total = COSTS_N_INSNS (3);
+ return true;
+
+ default:
+ break;
+ }
+
+ return false;
+}
+
+static bool
rx_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
{
/* We can always eliminate to the frame pointer.
@@ -3709,6 +3765,9 @@
#undef TARGET_MODES_TIEABLE_P
#define TARGET_MODES_TIEABLE_P rx_modes_tieable_p
+#undef TARGET_RTX_COSTS
+#define TARGET_RTX_COSTS rx_rtx_costs
+
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-rx.h"