An upcoming patch will convert hard_regno_nregs into an inline
function, which in turn allows hard_regno_nregs to be used as the
name of a targetm field.  This patch rewrites uses that are more
easily (and efficiently) written as END_REGNO.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.
Also tested by comparing the testsuite assembly output on at least one
target per CPU directory.  OK to install?

Richard


2017-09-11  Richard Sandiford  <richard.sandif...@linaro.org>

gcc/
        * config/frv/frv.c (FOR_EACH_REGNO): Use END_REGNO instead of
        hard_regno_nregs.
        * config/v850/v850.c (v850_reorg): Likewise.
        * reload.c (refers_to_regno_for_reload_p): Likewise.
        (find_equiv_reg): Likewise.
        * reload1.c (reload_reg_reaches_end_p): Likewise.

Index: gcc/config/frv/frv.c
===================================================================
--- gcc/config/frv/frv.c        2017-09-04 11:50:08.510328712 +0100
+++ gcc/config/frv/frv.c        2017-09-11 17:17:46.893352269 +0100
@@ -135,9 +135,7 @@ #define CLEAR_PACKING_FLAG(INSN) PUT_MOD
 
 /* Loop with REG set to each hard register in rtx X.  */
 #define FOR_EACH_REGNO(REG, X)                                         \
-  for (REG = REGNO (X);                                                        
\
-       REG < REGNO (X) + HARD_REGNO_NREGS (REGNO (X), GET_MODE (X));   \
-       REG++)
+  for (REG = REGNO (X); REG < END_REGNO (X); REG++)
 
 /* This structure contains machine specific function data.  */
 struct GTY(()) machine_function
Index: gcc/config/v850/v850.c
===================================================================
--- gcc/config/v850/v850.c      2017-09-04 11:50:08.540941953 +0100
+++ gcc/config/v850/v850.c      2017-09-11 17:17:46.893352269 +0100
@@ -1376,12 +1376,11 @@ v850_reorg (void)
                 for the register */
              if (GET_CODE (dest) == REG)
                {
-                 machine_mode mode = GET_MODE (dest);
                  int regno;
                  int endregno;
 
                  regno = REGNO (dest);
-                 endregno = regno + HARD_REGNO_NREGS (regno, mode);
+                 endregno = END_REGNO (dest);
 
                  if (!use_ep)
                    {
Index: gcc/reload.c
===================================================================
--- gcc/reload.c        2017-09-11 17:16:57.896550936 +0100
+++ gcc/reload.c        2017-09-11 17:17:46.894352229 +0100
@@ -6439,10 +6439,7 @@ refers_to_regno_for_reload_p (unsigned i
          return 0;
        }
 
-      return (endregno > r
-             && regno < r + (r < FIRST_PSEUDO_REGISTER
-                             ? hard_regno_nregs[r][GET_MODE (x)]
-                             : 1));
+      return endregno > r && regno < END_REGNO (x);
 
     case SUBREG:
       /* If this is a SUBREG of a hard reg, we can see exactly which
@@ -6889,15 +6886,11 @@ find_equiv_reg (rtx goal, rtx_insn *insn
     {
       int i;
       for (i = 0; i < n_reloads; i++)
-       if (rld[i].reg_rtx != 0 && rld[i].in)
-         {
-           int regno1 = REGNO (rld[i].reg_rtx);
-           int nregs1 = hard_regno_nregs[regno1]
-                                        [GET_MODE (rld[i].reg_rtx)];
-           if (regno1 < valueno + valuenregs
-               && regno1 + nregs1 > valueno)
-             return 0;
-         }
+       if (rld[i].reg_rtx != 0
+           && rld[i].in
+           && (int) REGNO (rld[i].reg_rtx) < valueno + valuenregs
+           && (int) END_REGNO (rld[i].reg_rtx) > valueno)
+         return 0;
     }
 
   if (goal_mem)
@@ -6963,15 +6956,11 @@ find_equiv_reg (rtx goal, rtx_insn *insn
              if (REG_P (dest))
                {
                  int xregno = REGNO (dest);
-                 int xnregs;
-                 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
-                   xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
-                 else
-                   xnregs = 1;
-                 if (xregno < regno + nregs && xregno + xnregs > regno)
+                 int end_xregno = END_REGNO (dest);
+                 if (xregno < regno + nregs && end_xregno > regno)
                    return 0;
                  if (xregno < valueno + valuenregs
-                     && xregno + xnregs > valueno)
+                     && end_xregno > valueno)
                    return 0;
                  if (goal_mem_addr_varies
                      && reg_overlap_mentioned_for_reload_p (dest, goal))
@@ -7006,16 +6995,12 @@ find_equiv_reg (rtx goal, rtx_insn *insn
                      if (REG_P (dest))
                        {
                          int xregno = REGNO (dest);
-                         int xnregs;
-                         if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
-                           xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
-                         else
-                           xnregs = 1;
+                         int end_xregno = END_REGNO (dest);
                          if (xregno < regno + nregs
-                             && xregno + xnregs > regno)
+                             && end_xregno > regno)
                            return 0;
                          if (xregno < valueno + valuenregs
-                             && xregno + xnregs > valueno)
+                             && end_xregno > valueno)
                            return 0;
                          if (goal_mem_addr_varies
                              && reg_overlap_mentioned_for_reload_p (dest,
@@ -7052,14 +7037,13 @@ find_equiv_reg (rtx goal, rtx_insn *insn
                      if (REG_P (dest))
                        {
                          int xregno = REGNO (dest);
-                         int xnregs
-                           = hard_regno_nregs[xregno][GET_MODE (dest)];
+                         int end_xregno = END_REGNO (dest);
 
                          if (xregno < regno + nregs
-                             && xregno + xnregs > regno)
+                             && end_xregno > regno)
                            return 0;
                          else if (xregno < valueno + valuenregs
-                                  && xregno + xnregs > valueno)
+                                  && end_xregno > valueno)
                            return 0;
                          else if (goal_mem_addr_varies
                                   && reg_overlap_mentioned_for_reload_p (dest,
Index: gcc/reload1.c
===================================================================
--- gcc/reload1.c       2017-09-11 17:16:57.897550882 +0100
+++ gcc/reload1.c       2017-09-11 17:17:46.895352189 +0100
@@ -5350,15 +5350,13 @@ reload_reg_reaches_end_p (unsigned int r
   for (i = reloadnum + 1; i < n_reloads; i++)
     {
       rtx reg;
-      int nregs;
 
       if (rld[i].opnum != opnum || rld[i].when_needed != type)
        continue;
       reg = rld[i].reg_rtx;
       if (reg == NULL_RTX)
        continue;
-      nregs = hard_regno_nregs[REGNO (reg)][GET_MODE (reg)];
-      if (regno >= REGNO (reg) && regno < REGNO (reg) + nregs)
+      if (regno >= REGNO (reg) && regno < END_REGNO (reg))
        return 0;
     }
   

Reply via email to