regalloc/debug: fix buggy print_hard_reg_set
authorHans-Peter Nilsson <hp@axis.com>
Tue, 11 Feb 2020 17:16:40 +0000 (18:16 +0100)
committerHans-Peter Nilsson <hp@axis.com>
Tue, 11 Feb 2020 17:16:40 +0000 (18:16 +0100)
* ira-conflicts.c (print_hard_reg_set): Correct output for sets
including FIRST_PSEUDO_REGISTER - 1.
* ira-color.c (print_hard_reg_set): Ditto.

Before, for a target with FIRST_PSEUDO_REGISTER 20, you'd get "19-18"
for (1<<19).  For (1<<18)|(1<<19), you'd get "18".

I was using ira-conflicts.c:print_hard_reg_set with a local
patch to gdbinit.in in a debug-session, and noticed the
erroneous output.  I see there's an almost identical function in
ira-color.c and on top of that, there's another function by the
same name and with similar semantics in sel-sched-dump.c, but
the last one doesn't try to print ranges.

gcc/ChangeLog
gcc/ira-color.c
gcc/ira-conflicts.c

index fa4e59e..7ddb6c3 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-11  Hans-Peter Nilsson  <hp@axis.com>
+
+       * ira-conflicts.c (print_hard_reg_set): Correct output for sets
+       including FIRST_PSEUDO_REGISTER - 1.
+       * ira-color.c (print_hard_reg_set): Ditto.
+
 2020-02-11  Stam Markianos-Wright  <stam.markianos-wright@arm.com>
 
        * config/arm/arm-builtins.c (enum arm_type_qualifiers): 
index 444cb1e..0bcc804 100644 (file)
@@ -480,24 +480,26 @@ first_common_ancestor_node (allocno_hard_regs_node_t first,
 static void
 print_hard_reg_set (FILE *f, HARD_REG_SET set, bool new_line_p)
 {
-  int i, start;
+  int i, start, end;
 
-  for (start = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+  for (start = end = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     {
-      if (TEST_HARD_REG_BIT (set, i))
+      bool reg_included = TEST_HARD_REG_BIT (set, i);
+
+      if (reg_included)
        {
-         if (i == 0 || ! TEST_HARD_REG_BIT (set, i - 1))
+         if (start == -1)
            start = i;
+         end = i;
        }
-      if (start >= 0
-         && (i == FIRST_PSEUDO_REGISTER - 1 || ! TEST_HARD_REG_BIT (set, i)))
+      if (start >= 0 && (!reg_included || i == FIRST_PSEUDO_REGISTER - 1))
        {
-         if (start == i - 1)
+         if (start == end)
            fprintf (f, " %d", start);
-         else if (start == i - 2)
-           fprintf (f, " %d %d", start, start + 1);
+         else if (start == end + 1)
+           fprintf (f, " %d %d", start, end);
          else
-           fprintf (f, " %d-%d", start, i - 1);
+           fprintf (f, " %d-%d", start, end);
          start = -1;
        }
     }
index 11d3a86..0220e72 100644 (file)
@@ -611,25 +611,27 @@ build_conflicts (void)
 static void
 print_hard_reg_set (FILE *file, const char *title, HARD_REG_SET set)
 {
-  int i, start;
+  int i, start, end;
 
   fputs (title, file);
-  for (start = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+  for (start = end = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     {
-      if (TEST_HARD_REG_BIT (set, i))
+      bool reg_included = TEST_HARD_REG_BIT (set, i);
+
+      if (reg_included)
        {
-         if (i == 0 || ! TEST_HARD_REG_BIT (set, i - 1))
+         if (start == -1)
            start = i;
+         end = i;
        }
-      if (start >= 0
-         && (i == FIRST_PSEUDO_REGISTER - 1 || ! TEST_HARD_REG_BIT (set, i)))
+      if (start >= 0 && (!reg_included || i == FIRST_PSEUDO_REGISTER - 1))
        {
-         if (start == i - 1)
+         if (start == end)
            fprintf (file, " %d", start);
-         else if (start == i - 2)
-           fprintf (file, " %d %d", start, start + 1);
+         else if (start == end + 1)
+           fprintf (file, " %d %d", start, end);
          else
-           fprintf (file, " %d-%d", start, i - 1);
+           fprintf (file, " %d-%d", start, end);
          start = -1;
        }
     }