Update RTX costs to reflect better the ARC architecture.

Ok to apply?
Claudiu

gcc/
xxxx-xx-xx  Claudiu Zissulescu  <claz...@synopsys.com>

        * config/arc/arc.c (arc_rtx_costs): Update costs.

/gcc/testsuite
xxxx-xx-xx  Claudiu Zissulescu  <claz...@synopsys.com>

        * gcc.target/arc/jumptables.c: Update test.
---
 gcc/config/arc/arc.c                     | 69 +++++++++++++-----------
 gcc/testsuite/gcc.target/arc/jumptable.c |  2 +-
 2 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index f398c4a0086..20dfae66370 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -5569,41 +5569,39 @@ arc_rtx_costs (rtx x, machine_mode mode, int outer_code,
     case CONST_INT:
       {
        bool nolimm = false; /* Can we do without long immediate?  */
-       bool fast = false; /* Is the result available immediately?  */
-       bool condexec = false; /* Does this allow conditiobnal execution?  */
-       bool compact = false; /* Is a 16 bit opcode available?  */
-       /* CONDEXEC also implies that we can have an unconditional
-          3-address operation.  */
 
-       nolimm = compact = condexec = false;
+       nolimm = false;
        if (UNSIGNED_INT6 (INTVAL (x)))
-         nolimm = condexec = compact = true;
+         nolimm = true;
        else
          {
-           if (SMALL_INT (INTVAL (x)))
-             nolimm = fast = true;
            switch (outer_code)
              {
              case AND: /* bclr, bmsk, ext[bw] */
                if (satisfies_constraint_Ccp (x) /* bclr */
                    || satisfies_constraint_C1p (x) /* bmsk */)
-                 nolimm = fast = condexec = compact = true;
+                 nolimm = true;
                break;
              case IOR: /* bset */
                if (satisfies_constraint_C0p (x)) /* bset */
-                 nolimm = fast = condexec = compact = true;
+                 nolimm = true;
                break;
              case XOR:
                if (satisfies_constraint_C0p (x)) /* bxor */
-                 nolimm = fast = condexec = true;
+                 nolimm = true;
                break;
+             case SET:
+               if (UNSIGNED_INT8 (INTVAL (x)))
+                 nolimm = true;
+               if (satisfies_constraint_Chi (x))
+                 nolimm = true;
+               if (satisfies_constraint_Clo (x))
+                 nolimm = true;
              default:
                break;
              }
          }
-       /* FIXME: Add target options to attach a small cost if
-          condexec / compact is not true.  */
-       if (nolimm)
+       if (nolimm && !speed)
          {
            *total = 0;
            return true;
@@ -5616,7 +5614,7 @@ arc_rtx_costs (rtx x, machine_mode mode, int outer_code,
     case CONST:
     case LABEL_REF:
     case SYMBOL_REF:
-      *total = COSTS_N_INSNS (1);
+      *total = speed ? COSTS_N_INSNS (1) : COSTS_N_INSNS (4);
       return true;
 
     case CONST_DOUBLE:
@@ -5642,16 +5640,10 @@ arc_rtx_costs (rtx x, machine_mode mode, int outer_code,
     case LSHIFTRT:
       if (TARGET_BARREL_SHIFTER)
        {
-         /* If we want to shift a constant, we need a LIMM.  */
-         /* ??? when the optimizers want to know if a constant should be
-            hoisted, they ask for the cost of the constant.  OUTER_CODE is
-            insufficient context for shifts since we don't know which operand
-            we are looking at.  */
          if (CONSTANT_P (XEXP (x, 0)))
            {
-             *total += (COSTS_N_INSNS (2)
-                        + rtx_cost (XEXP (x, 1), mode, (enum rtx_code) code,
-                                    0, speed));
+             *total += rtx_cost (XEXP (x, 1), mode, (enum rtx_code) code,
+                                 0, speed);
              return true;
            }
          *total = COSTS_N_INSNS (1);
@@ -5671,7 +5663,13 @@ arc_rtx_costs (rtx x, machine_mode mode, int outer_code,
 
     case DIV:
     case UDIV:
-      if (speed)
+      if (GET_MODE_CLASS (mode) == MODE_FLOAT
+         && (TARGET_FP_SP_SQRT || TARGET_FP_DP_SQRT))
+       *total = COSTS_N_INSNS(1);
+      else if (GET_MODE_CLASS (mode) == MODE_INT
+              && TARGET_DIVREM)
+       *total = COSTS_N_INSNS(1);
+      else if (speed)
        *total = COSTS_N_INSNS(30);
       else
        *total = COSTS_N_INSNS(1);
@@ -5684,19 +5682,28 @@ arc_rtx_costs (rtx x, machine_mode mode, int outer_code,
        *total= arc_multcost;
       /* We do not want synth_mult sequences when optimizing
         for size.  */
-      else if (TARGET_MUL64_SET || TARGET_ARC700_MPY)
+      else if (TARGET_ANY_MPY)
        *total = COSTS_N_INSNS (1);
       else
        *total = COSTS_N_INSNS (2);
       return false;
+
     case PLUS:
+      if (outer_code == MEM && CONST_INT_P (XEXP (x, 1))
+         && RTX_OK_FOR_OFFSET_P (mode, XEXP (x, 1)))
+       {
+         *total = 0;
+         return true;
+       }
+
       if ((GET_CODE (XEXP (x, 0)) == ASHIFT
           && _1_2_3_operand (XEXP (XEXP (x, 0), 1), VOIDmode))
           || (GET_CODE (XEXP (x, 0)) == MULT
               && _2_4_8_operand (XEXP (XEXP (x, 0), 1), VOIDmode)))
        {
-         *total += (rtx_cost (XEXP (x, 1), mode, PLUS, 0, speed)
-                    + rtx_cost (XEXP (XEXP (x, 0), 0), mode, PLUS, 1, speed));
+         if (CONSTANT_P (XEXP (x, 1)) && !speed)
+           *total += COSTS_N_INSNS (4);
+         *total += rtx_cost (XEXP (XEXP (x, 0), 0), mode, PLUS, 1, speed);
          return true;
        }
       return false;
@@ -5706,11 +5713,13 @@ arc_rtx_costs (rtx x, machine_mode mode, int outer_code,
           || (GET_CODE (XEXP (x, 1)) == MULT
               && _2_4_8_operand (XEXP (XEXP (x, 1), 1), VOIDmode)))
        {
-         *total += (rtx_cost (XEXP (x, 0), mode, PLUS, 0, speed)
-                    + rtx_cost (XEXP (XEXP (x, 1), 0), mode, PLUS, 1, speed));
+         if (CONSTANT_P (XEXP (x, 0)) && !speed)
+           *total += COSTS_N_INSNS (4);
+         *total += rtx_cost (XEXP (XEXP (x, 1), 0), mode, PLUS, 1, speed);
          return true;
        }
       return false;
+
     case COMPARE:
       {
        rtx op0 = XEXP (x, 0);
diff --git a/gcc/testsuite/gcc.target/arc/jumptable.c 
b/gcc/testsuite/gcc.target/arc/jumptable.c
index fbc58e33149..ffbcf93e164 100644
--- a/gcc/testsuite/gcc.target/arc/jumptable.c
+++ b/gcc/testsuite/gcc.target/arc/jumptable.c
@@ -31,4 +31,4 @@ int switchCase(int value, int b)
 }
 
 /* { dg-final { scan-assembler-times "bih" 1 } } */
-/* { dg-final { scan-assembler-times "b_s" 8 } } */
+/* { dg-final { scan-assembler-times "b_s" 6 } } */
-- 
2.21.0

Reply via email to