GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
i386

i386: Use separate unspecs for CRC32 widths

CRC32 instruction handling on i386 is fixed to prevent incorrect constant folding.

The i386 architecture’s CRC32 instructions previously used a single internal representation (UNSPEC_CRC32) for all operand widths. This allowed common subexpression elimination (CSE) to incorrectly merge results of CRC32 operations with different widths when a constant was used. This change introduces distinct internal representations for each width (byte, word, long, quad) to prevent such misoptimizations and also adds support for the 64-bit zero-extended CRC32B.

In Details

The GCC i386 backend used a generic UNSPEC_CRC32 for all variants of the CRC32 instruction. When the second operand was a constant, the mode information was lost, causing CSE to treat different-width CRC32 operations (e.g., _mm_crc32_u16 vs. _mm_crc32_u32) as equivalent. This commit replaces UNSPEC_CRC32 with specific unspecs (UNSPEC_CRC32B, UNSPEC_CRC32W, UNSPEC_CRC32L, UNSPEC_CRC32Q) to preserve width information and correct CSE behavior. It also adds a new instruction pattern for the zero-extended 64-bit CRC32B operation.

For Context
CRC32
A cyclic redundancy check algorithm used for error detection, with specific hardware instructions available on x86 processors for performance.
UNSPEC
An internal GCC representation for machine-specific operations that do not map directly to a standard RTL (Register Transfer Language) construct.
CSE
Common Subexpression Elimination is a compiler optimization that detects identical expressions and replaces subsequent occurrences with a temporary variable holding the result of the first.
i386
The Intel 80386 processor architecture, commonly referred to as x86-32. GCC targets this architecture for 32-bit code generation on compatible processors.
Filed Under: i386optimizationbugfix