i386: Add const folding for crc32 instructions
Enables constant folding for x86 CRC32 intrinsics.
This commit adds constant folding support for the SSE4.2 CRC32 intrinsics (_mm_crc32_u8, _mm_crc32_u16, _mm_crc32_u32, _mm_crc32_u64) on the i386 architecture. It leverages the calculate_reversed_crc function with the CRC32C polynomial to precompute results for constant arguments. Additionally, it removes an assertion in hwint.cc that previously restricted folding when crc_bits was greater than or equal to data_bits, enabling folding for _mm_crc32_u64.
In Details
The ix86_fold_builtin function in config/i386/i386.cc now supports constant folding for the SSE4.2 _mm_crc32_* intrinsics. This is achieved by calling calculate_reversed_crc with the CRC32C polynomial. The commit also relaxes the crc_bits >= data_bits assertion in hwint.cc, which was preventing folding of _mm_crc32_u64 where crc_bits (32) is less than data_bits (64) but the loop correctly resolves. A new test case gcc.target/i386/crc32-const-fold.c is added.
- const folding
- A compiler optimization technique where expressions with constant operands are evaluated at compile time rather than runtime. This can improve performance by reducing runtime computation.
- i386
- The original 32-bit Intel x86 architecture. GCC supports this architecture, often referred to as x86.
- SSE4.2
- Streaming SIMD Extensions 4.2. A set of instruction set extensions for x86 processors that includes instructions for string processing and cyclic redundancy checks (CRC).
- intrinsics
- Special functions or instructions that allow programmers to access hardware-specific operations or low-level features directly from high-level code, often providing performance benefits.