Slim RTL dumps show unspec numbers as decimal numbers. These are (a) meaningless and (b) if you manage to remember any of them, they're not stable against some random md file in your target changing the enumerations.

1) This patch emits the UNSPEC or UNSPECV name. I strip the leading UNSPEC_?, leaving FOO or V_FOO depending. And also elide the space that prefixed it -- no loss of readability, the previous char is ']'

So instead of:
  unspec/v[r176,0xc] 365
one gets:
  unspec/v[r176,0xc]V_SFPCONFIG
which means a lot more (to me at least).

An additional problem is also addressed in both slim and regular rtl printers. For unspec_volatile they fall back to printing the UNSPEC enum, if the value is out of range. But this is wrong. If there are *any* UNSPECV values, *all* unspec_volatiles should use them. There's no guarantee that the UNSPEC value one might have intended doesn't match an UNSPECV value from some (other) md file in your target. (As I found out and addressed with a recent patch concerning Risc-V atomics.) Thus this patch only does the fallback if there are no UNSPECV values.

ok?

nathan
--
Nathan Sidwell
From 624ae7fdee19f3d01681398a460b242511b3cdb5 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <[email protected]>
Date: Fri, 10 Jul 2026 14:21:38 -0400
Subject: [PATCH] Show UNSPEC names on slim rtl dump

	gcc/
	* print-rtl.cc (rtx_writer::print_rtx_operand_code_i): Don't
	fallback to UNSPEC enums if there are any UNSPECV enums.
	(print_exp): Print unspec/unspecv name, when available.
---
 gcc/print-rtl.cc | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/gcc/print-rtl.cc b/gcc/print-rtl.cc
index 8123e2abe80..b969c6d8229 100644
--- a/gcc/print-rtl.cc
+++ b/gcc/print-rtl.cc
@@ -508,7 +508,11 @@ rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx)
 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
   else if (idx == 1
 	   && (GET_CODE (in_rtx) == UNSPEC
-	       || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
+#if !(NUM_UNSPECV_VALUES > 0)
+	       // Only accept unspec_volatiles, if there's no unspecv enum.
+	       || GET_CODE (in_rtx) == UNSPEC_VOLATILE
+#endif
+	       || false)
 	   && XINT (in_rtx, 1) >= 0
 	   && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
     fprintf (m_outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
@@ -1610,8 +1614,36 @@ print_exp (pretty_printer *pp, const_rtx x, int verbose)
 	      pp_comma (pp);
 	    print_pattern (pp, XVECEXP (x, 0, i), verbose);
 	  }
-	pp_string (pp, "] ");
-	pp_decimal_int (pp, XINT (x, 1));
+	pp_string (pp, "]");
+	const char *str = nullptr;
+	auto unspec = XINT (x, 1);
+#if !defined(GENERATOR_FILE)
+	if (unspec < 0)
+	  ;
+#if NUM_UNSPECV_VALUES > 0
+	else if (GET_CODE (x) == UNSPEC_VOLATILE
+		 && unspec < NUM_UNSPECV_VALUES)
+	  str = unspecv_strings[unspec];
+#endif
+#if NUM_UNSPEC_VALUES > 0
+	else if (true
+#if NUM_UNSPECV_VALUES > 0
+		 // Only accept unspec_volatiles, if there's no unspecv enum.
+		 && GET_CODE (x) == UNSPEC
+#endif
+		 && unspec < NUM_UNSPEC_VALUES)
+	  str = unspec_strings[unspec];
+#endif
+#endif
+	if (str)
+	  {
+	    // Strip leading UNSPEC[_] leaving FOO or V_FOO by convention.
+	    if (0 == strncmp (str, "UNSPEC", 6))
+	      str += 6 + (str[6] == '_');
+	    pp_string (pp, str);
+	  }
+	else
+	  pp_decimal_int (pp, unspec);
       }
       break;
     default:
-- 
2.55.0

Reply via email to