]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
simplify-rtx: Split out native_decode_int
authorRichard Sandiford <richard.sandiford@arm.com>
Mon, 28 Apr 2025 13:40:09 +0000 (14:40 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Mon, 28 Apr 2025 13:40:09 +0000 (14:40 +0100)
native_decode_rtx handles integer modes by building up a wide_int
and then converting it to an rtx.  This patch splits out the
wide_int part, so that callers who don't want an rtx can avoid
creating garbage rtl.

gcc/
* rtl.h (native_decode_int): Declare.
* simplify-rtx.cc (native_decode_int): New function, split out from...
(native_decode_rtx): ...here.

gcc/rtl.h
gcc/simplify-rtx.cc

index 3b676c46880527128ca6fd211292ba6d38e5eda2..cc25aed1f49425bb3b28a69a806d7a2b0f79f1db 100644 (file)
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2443,6 +2443,8 @@ extern void get_full_rtx_cost (rtx, machine_mode, enum rtx_code, int,
                               struct full_rtx_costs *);
 extern bool native_encode_rtx (machine_mode, rtx, vec<target_unit> &,
                               unsigned int, unsigned int);
+extern wide_int native_decode_int (const vec<target_unit> &, unsigned int,
+                                  unsigned int, unsigned int);
 extern rtx native_decode_rtx (machine_mode, const vec<target_unit> &,
                              unsigned int);
 extern rtx native_decode_vector_rtx (machine_mode, const vec<target_unit> &,
index 06b52ca80037c65ac59d939ea43f4cf9e9976139..d9aa0493a186ad9586c01259409da51fa351acda 100644 (file)
@@ -7713,6 +7713,28 @@ native_decode_vector_rtx (machine_mode mode, const vec<target_unit> &bytes,
   return builder.build ();
 }
 
+/* Extract a PRECISION-bit integer from bytes [FIRST_BYTE, FIRST_BYTE + SIZE)
+   of target memory image BYTES.  */
+
+wide_int
+native_decode_int (const vec<target_unit> &bytes, unsigned int first_byte,
+                  unsigned int size, unsigned int precision)
+{
+  /* Pull the bytes msb first, so that we can use simple
+     shift-and-insert wide_int operations.  */
+  wide_int result (wi::zero (precision));
+  for (unsigned int i = 0; i < size; ++i)
+    {
+      unsigned int lsb = (size - i - 1) * BITS_PER_UNIT;
+      /* Always constant because the inputs are.  */
+      unsigned int subbyte
+       = subreg_size_offset_from_lsb (1, size, lsb).to_constant ();
+      result <<= BITS_PER_UNIT;
+      result |= bytes[first_byte + subbyte];
+    }
+  return result;
+}
+
 /* Read an rtx of mode MODE from the target memory image given by BYTES,
    starting at byte FIRST_BYTE.  Each element of BYTES contains BITS_PER_UNIT
    bits and the bytes are in target memory order.  The image has enough
@@ -7738,19 +7760,9 @@ native_decode_rtx (machine_mode mode, const vec<target_unit> &bytes,
   if (is_a <scalar_int_mode> (mode, &imode)
       && GET_MODE_PRECISION (imode) <= MAX_BITSIZE_MODE_ANY_INT)
     {
-      /* Pull the bytes msb first, so that we can use simple
-        shift-and-insert wide_int operations.  */
-      unsigned int size = GET_MODE_SIZE (imode);
-      wide_int result (wi::zero (GET_MODE_PRECISION (imode)));
-      for (unsigned int i = 0; i < size; ++i)
-       {
-         unsigned int lsb = (size - i - 1) * BITS_PER_UNIT;
-         /* Always constant because the inputs are.  */
-         unsigned int subbyte
-           = subreg_size_offset_from_lsb (1, size, lsb).to_constant ();
-         result <<= BITS_PER_UNIT;
-         result |= bytes[first_byte + subbyte];
-       }
+      auto result = native_decode_int (bytes, first_byte,
+                                      GET_MODE_SIZE (imode),
+                                      GET_MODE_PRECISION (imode));
       return immed_wide_int_const (result, imode);
     }