https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116538

            Bug ID: 116538
           Summary: GET_MODE_BITSIZE() returns wrong value for PSImode
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alancf0 at gmail dot com
  Target Milestone: ---
            Target: msp430-none-elf

Some targets (ie, msp430-none-elf with the -mlarge flag) have size_t and
pointer types with a size between HImode and SImode; the size of this type is
often not a multiple of 8 bits. In the case of msp430 with -mlarge, PSImode is
20 bits. The current implementation of GET_MODE_BITSIZE() is as follows:

/* Return the base GET_MODE_BITSIZE value for MODE.  */

ALWAYS_INLINE poly_uint16
mode_to_bits (machine_mode mode)
{
  return mode_to_bytes (mode) * BITS_PER_UNIT; 
}


This obviously does not return the correct value for types whose size is not a
multiple of one byte. One possible patch, which mirrors the above
mode_to_bytes():

diff -ur gcc-12.2.0/gcc/machmode.h ../gcc-12.2.0/gcc/machmode.h
--- gcc-12.2.0/gcc/machmode.h   2022-08-19 01:09:52.940667079 -0700
+++ ../gcc-12.2.0/gcc/machmode.h        2024-08-29 21:51:01.099313215 -0700
@@ -558,7 +558,12 @@
 ALWAYS_INLINE poly_uint16
 mode_to_bits (machine_mode mode)
 {
-  return mode_to_bytes (mode) * BITS_PER_UNIT;
+#if GCC_VERSION >= 4001
+  return (__builtin_constant_p (mode)
+         ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
+#else
+  return mode_unit_precision[mode];
+#endif
 }

 /* Return the base GET_MODE_PRECISION value for MODE.  */

Note: I have not tested this patch extensively; perhaps in context it is
necessary for mode_to_bits to return a value which is a multiple of 8.

Reply via email to