aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Sayle <roger@nextmovesoftware.com>2022-05-30 21:23:15 +0100
committerRoger Sayle <roger@nextmovesoftware.com>2022-05-30 21:23:15 +0100
commit2a12adfa8bd61e46538ebd97ae927d594843026a (patch)
tree2c993ead0156141eefd817d4eef5706613e66705
parent43201f2c2173894bf7c423cad6da1c21567e06c0 (diff)
downloadgcc-2a12adfa8bd61e46538ebd97ae927d594843026a.zip
gcc-2a12adfa8bd61e46538ebd97ae927d594843026a.tar.gz
gcc-2a12adfa8bd61e46538ebd97ae927d594843026a.tar.bz2
Make the default rtx_costs of MULT/DIV variants consistent.
GCC's middle-end provides a default cost model for RTL expressions, for backends that don't specify their own instruction timings, that can be summarized as multiplications are COSTS_N_INSNS(4), divisions are COSTS_N_INSNS(7) and all other operations are COSTS_N_INSNS(1). This patch tweaks the above definition so that fused-multiply-add (FMA) and high-part multiplications cost the same as regular multiplications, or more importantly aren't (by default) considered less expensive. Likewise the saturating forms of multiplication and division cost the same as the regular variants. These values can always be changed by the target, but the goal is to avoid RTL expansion substituting a suitable operation with its saturating equivalent because it (accidentally) looks much cheaper. For example, PR 89845 is about implementing division/modulus via highpart multiply, which may accidentally look extremely cheap. 2022-05-30 Roger Sayle <roger@nextmovesoftware.com> gcc/ChangeLog * rtlanal.cc (rtx_cost) <MULT>: Treat FMA, SS_MULT, US_MULT, SMUL_HIGHPART and UMUL_HIGHPART as having the same cost as MULT. <DIV>: Likewise, SS_DIV and US_DIV have the same default as DIV.
-rw-r--r--gcc/rtlanal.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index 7c29682..d78cc60 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -4578,6 +4578,11 @@ rtx_cost (rtx x, machine_mode mode, enum rtx_code outer_code,
switch (code)
{
case MULT:
+ case FMA:
+ case SS_MULT:
+ case US_MULT:
+ case SMUL_HIGHPART:
+ case UMUL_HIGHPART:
/* Multiplication has time-complexity O(N*N), where N is the
number of units (translated from digits) when using
schoolbook long multiplication. */
@@ -4587,6 +4592,8 @@ rtx_cost (rtx x, machine_mode mode, enum rtx_code outer_code,
case UDIV:
case MOD:
case UMOD:
+ case SS_DIV:
+ case US_DIV:
/* Similarly, complexity for schoolbook long division. */
total = factor * factor * COSTS_N_INSNS (7);
break;