GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
middle-end Performance Win

Fix CRC computation for 24-iteration loops.

Corrects CRC calculation in GCC's middle-end for specific 24-iteration loops.

This commit fixes an issue in GCC’s middle-end CRC pass where loops with exactly 24 iterations were producing incorrect results. The CRC pass incorrectly created a 24-bit data type and derived the processing size from its mode, leading it to process 4 bytes instead of the intended 3. The fix modifies the CRC table expanders to use a passed bit size instead of inferring it from the mode, ensuring correct computation.

In Details

The crc_table_based built-in functions in GCC's middle-end, particularly for CRC32 variants, have a bug when processing 24-iteration loops. The expand_builtin_crc_table_based and related functions construct a SImode (32-bit integer) type for a 24-bit CRC computation. The table-based expanders then incorrectly use TYPE_PRECISION to determine the data size, leading to 4-byte processing instead of 3. This patch updates the API to explicitly pass the data_bit_size to the expander functions, ensuring correct handling for 24-bit CRC computations.

For Context
CRC
Cyclic Redundancy Check, an error-detection code used to detect accidental changes to raw data. GCC has built-in functions for calculating CRC values.
middle-end
The intermediate representation (IR) processing phase of a compiler, situated between the front-end (parsing and syntax analysis) and the back-end (code generation).
SImode
GCC's internal representation mode for a single integer (32 bits on most common targets).
mode
In GCC's internal representation, a 'mode' defines the data type and size of a value (e.g., SImode for integer, DImode for double integer, SFmode for single-precision float).
expander
A compiler component that replaces a high-level or complex instruction or operation with a sequence of simpler, lower-level operations that achieve the same result.
Filed Under: middle-endCRCoptimizationloops