On 11/18/26 1:42 AM, [email protected] wrote:
From: Kyrylo Tkachov <[email protected]>

The CRC loop pass accepts any iteration count up to the CRC width.  When
the CRC is xor-ed with the data before the loop, it builds a data argument
of a non-standard integer type with one bit per iteration.  The expander
for IFN_CRC and IFN_CRC_REV uses TYPE_MODE of the data type, so for a
24 iteration loop it processes 32 bits and returns the value after 32
shift steps instead of 24:

   for (int i = 0; i < 24; i++)
     crc = (crc & 1) ? (crc >> 1) ^ 0xEDB88320 : crc >> 1;

Only accept loops whose data size is the precision of an integer mode,
in validate_crc_and_data.  When the data is a PHI, also require its type
to have the precision of its mode.  Add an assert in expand_crc_optab_fn so
that such a type turns into an ICE rather than wrong code.

Bootstrapped and tested on aarch64-none-linux-gnu.
Ok for trunk?
Thanks,
Kyrill

gcc/ChangeLog:

        PR middle-end/127984
        * gimple-crc-optimization.cc (crc_optimization::validate_crc_and_data):
        Reject data sizes that are not the precision of an integer mode
        and data PHIs whose type does not have the precision of its mode.
        * internal-fn.cc (expand_crc_optab_fn): Assert that the data type
        precision matches its mode.

gcc/testsuite/ChangeLog:

        PR middle-end/127984
        * gcc.dg/pr127984.c: New test.

Signed-off-by: Kyrylo Tkachov <[email protected]>
I was exchanging mail with someone recently on this  The right fix is to pass in the size rather than depending on the mode to provide the size.  We might still need to restrict to a byte granule, but there's no inherent need to reject sizes like 24, 40, 48, etc bits.

Jeff

Reply via email to