This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[9/9] Simplify register bitmap operations


After the previous changes, several callers are left with code like:

  if (HARD_REGISTER_P (x))
    bitmap_foo_range (x, REGNO (x), REG_NREGS (x));
  else
    bitmap_foo (x, REGNO (x));

These might as well now be:

  if (REG_NREGS (x) > 1)
    bitmap_foo_range (x, REGNO (x), REG_NREGS (x));
  else
    bitmap_foo (x, REGNO (x));

since REG_NREGS is as cheap to test, and since single-register hard REGs
are the common case.  But if separating out the cases is a win -- and it
seems to be, very slightly -- then it would be better to add the shortcut
to the range functions themselves.


gcc/
	* bitmap.c (bitmap_set_range): Handle count==1 specially.
	(bitmap_clear_range): Likewise.
	* cfgcleanup.c (mark_effect): Use bitmap_clear_range and
	bitmap_set_range unconditionally.
	* df-problems.c (df_simulate_one_insn_forwards): Likewise.
	* df-scan.c (df_mark_reg): Likewise.
	* haifa-sched.c (setup_ref_regs): Likewise.
	* sched-rgn.c (update_live_1): Likewise.

Index: gcc/bitmap.c
===================================================================
--- gcc/bitmap.c	2015-05-18 08:38:25.845752816 +0100
+++ gcc/bitmap.c	2015-05-18 08:38:25.841752865 +0100
@@ -1212,6 +1212,12 @@ bitmap_set_range (bitmap head, unsigned
   if (!count)
     return;
 
+  if (count == 1)
+    {
+      bitmap_set_bit (head, start);
+      return;
+    }
+
   first_index = start / BITMAP_ELEMENT_ALL_BITS;
   end_bit_plus1 = start + count;
   last_index = (end_bit_plus1 - 1) / BITMAP_ELEMENT_ALL_BITS;
@@ -1311,6 +1317,12 @@ bitmap_clear_range (bitmap head, unsigne
   if (!count)
     return;
 
+  if (count == 1)
+    {
+      bitmap_clear_bit (head, start);
+      return;
+    }
+
   first_index = start / BITMAP_ELEMENT_ALL_BITS;
   end_bit_plus1 = start + count;
   last_index = (end_bit_plus1 - 1) / BITMAP_ELEMENT_ALL_BITS;
Index: gcc/cfgcleanup.c
===================================================================
--- gcc/cfgcleanup.c	2015-05-18 08:38:25.845752816 +0100
+++ gcc/cfgcleanup.c	2015-05-18 08:38:25.841752865 +0100
@@ -222,22 +222,15 @@ try_simplify_condjump (basic_block cbran
 static bool
 mark_effect (rtx exp, regset nonequal)
 {
-  int regno;
   rtx dest;
   switch (GET_CODE (exp))
     {
       /* In case we do clobber the register, mark it as equal, as we know the
 	 value is dead so it don't have to match.  */
     case CLOBBER:
-      if (REG_P (XEXP (exp, 0)))
-	{
-	  dest = XEXP (exp, 0);
-	  regno = REGNO (dest);
-	  if (HARD_REGISTER_NUM_P (regno))
-	    bitmap_clear_range (nonequal, regno, REG_NREGS (dest));
-	  else
-	    bitmap_clear_bit (nonequal, regno);
-	}
+      dest = XEXP (exp, 0);
+      if (REG_P (dest))
+	bitmap_clear_range (nonequal, REGNO (dest), REG_NREGS (dest));
       return false;
 
     case SET:
@@ -248,11 +241,7 @@ mark_effect (rtx exp, regset nonequal)
 	return false;
       if (!REG_P (dest))
 	return true;
-      regno = REGNO (dest);
-      if (HARD_REGISTER_NUM_P (regno))
-	bitmap_set_range (nonequal, regno, REG_NREGS (dest));
-      else
-	bitmap_set_bit (nonequal, regno);
+      bitmap_set_range (nonequal, REGNO (dest), REG_NREGS (dest));
       return false;
 
     default:
Index: gcc/df-problems.c
===================================================================
--- gcc/df-problems.c	2015-05-18 08:38:25.845752816 +0100
+++ gcc/df-problems.c	2015-05-18 08:38:25.845752816 +0100
@@ -3574,11 +3574,7 @@ df_simulate_one_insn_forwards (basic_blo
 	case REG_UNUSED:
 	  {
 	    rtx reg = XEXP (link, 0);
-	    int regno = REGNO (reg);
-	    if (HARD_REGISTER_NUM_P (regno))
-	      bitmap_clear_range (live, regno, REG_NREGS (reg));
-	    else
-	      bitmap_clear_bit (live, regno);
+	    bitmap_clear_range (live, REGNO (reg), REG_NREGS (reg));
 	  }
 	  break;
 	default:
Index: gcc/df-scan.c
===================================================================
--- gcc/df-scan.c	2015-05-18 08:38:25.845752816 +0100
+++ gcc/df-scan.c	2015-05-18 08:38:25.841752865 +0100
@@ -3518,15 +3518,7 @@ df_get_eh_block_artificial_uses (bitmap
 static void
 df_mark_reg (rtx reg, void *vset)
 {
-  bitmap set = (bitmap) vset;
-  int regno = REGNO (reg);
-
-  gcc_assert (GET_MODE (reg) != BLKmode);
-
-  if (regno < FIRST_PSEUDO_REGISTER)
-    bitmap_set_range (set, regno, REG_NREGS (reg));
-  else
-    bitmap_set_bit (set, regno);
+  bitmap_set_range ((bitmap) vset, REGNO (reg), REG_NREGS (reg));
 }
 
 
Index: gcc/haifa-sched.c
===================================================================
--- gcc/haifa-sched.c	2015-05-18 08:38:25.845752816 +0100
+++ gcc/haifa-sched.c	2015-05-18 08:38:25.845752816 +0100
@@ -1032,17 +1032,13 @@ initiate_reg_pressure_info (bitmap live)
 static void
 setup_ref_regs (rtx x)
 {
-  int i, j, regno;
+  int i, j;
   const RTX_CODE code = GET_CODE (x);
   const char *fmt;
 
   if (REG_P (x))
     {
-      regno = REGNO (x);
-      if (HARD_REGISTER_NUM_P (regno))
-	bitmap_set_range (region_ref_regs, regno, REG_NREGS (x));
-      else
-	bitmap_set_bit (region_ref_regs, REGNO (x));
+      bitmap_set_range (region_ref_regs, REGNO (x), REG_NREGS (x));
       return;
     }
   fmt = GET_RTX_FORMAT (code);
Index: gcc/sched-rgn.c
===================================================================
--- gcc/sched-rgn.c	2015-05-18 08:38:25.845752816 +0100
+++ gcc/sched-rgn.c	2015-05-18 08:38:25.845752816 +0100
@@ -1801,11 +1801,7 @@ update_live_1 (int src, rtx x)
       for (i = 0; i < candidate_table[src].update_bbs.nr_members; i++)
 	{
 	  basic_block b = candidate_table[src].update_bbs.first_member[i];
-
-	  if (HARD_REGISTER_NUM_P (regno))
-	    bitmap_set_range (df_get_live_in (b), regno, REG_NREGS (reg));
-	  else
-	    bitmap_set_bit (df_get_live_in (b), regno);
+	  bitmap_set_range (df_get_live_in (b), regno, REG_NREGS (reg));
 	}
     }
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]