Reject table-based CRC optabs for size optimization.
RISC-V CRC optimization now avoids large lookup tables when optimizing for code size.
RISC-V CRC optimization logic has been updated to prevent the use of a large, 256-entry lookup table when optimizing for code size (-Os, -Oz). This table-based fallback significantly increases code size, especially when CLMUL expansion is unavailable. The compiler now checks TARGET_OPTAB_SUPPORTED_P for crc_rev_optab, allowing the table fallback only for speed optimizations, and for size optimizations only when hardware CLMUL extensions (Zbc, Zbkc, Zvbc) are available and the result mode is small.
In Details
The riscv_optab_supported_p function is introduced to implement TARGET_OPTAB_SUPPORTED_P for the crc_rev_optab. The profitability check for PR middle-end/124900 requires targets to indicate suitability for both speed and size. The RISC-V reversed CRC optab, which defaults to a 256-entry lookup table when CLMUL expansion is missing, was incorrectly deemed suitable for size. This commit restricts its use for size optimization to cases where CLMUL is available and the result mode is narrower than word_mode.
- CRC optab
- An operation table entry for Cyclic Redundancy Check (CRC) calculations. These tables map abstract operations to specific machine instructions or sequences.
- CLMUL
- Carry-Less Multiplication. An instruction set extension found in various architectures (like Intel's PCLMULQDQ and ARM's CLMUL) that performs multiplication without carry propagation, useful for cryptographic and CRC operations.
- optab
- Operation table. A data structure in GCC that maps machine-independent operations to target-specific instructions or code sequences.
- word_mode
- GCC's internal representation for the natural machine word size of the target architecture (e.g., 32 bits on RV32, 64 bits on RV64).
- Zbc, Zbkc, Zvbc
- RISC-V standard extensions that provide CLMUL (Carry-Less Multiplication) capabilities.