RISC-V: Refactor macro-fusion helper predicates
GCC refactors RISC-V macro-fusion helpers for better code reuse and accuracy.
GCC’s RISC-V backend has undergone a significant refactoring of its macro-fusion helper functions. This change factors out common RTL parsing logic, improving code reuse and maintainability. It enhances the accuracy of destination matching by considering subregister bit positions and preserves pre-allocation destination overmatching while validating real producer-consumer dependencies. The introduction of parameterized classifiers allows later fusion recognizers to share structural matching logic without duplicating microarchitecture-specific constraints, leading to a more robust and extensible fusion framework.
In Details
This commit is a substantial cleanup and generalization of the RISC-V macro-fusion infrastructure in GCC. It addresses several key areas: 1) Factoring common RTL parsing into new helper functions (riscv_fuse_sets_p, riscv_set_extract_word_binary_p, etc.) to reduce duplication. 2) Improving register comparison by distinguishing subregister bit positions (riscv_fuse_same_reg_p) and handling hard-register SUBREGs (riscv_fuse_same_dest_p). 3) Generalizing instruction classification by introducing parameterized classifiers (e.g., riscv_insn_is_addi_type_p) and sched_fusion_type bitmask…
- macro-fusion
- An optimization technique where the compiler combines two or more adjacent instructions into a single, more efficient instruction or sequence, provided specific conditions (like register dependencies) are met.
- RTL
- Register Transfer Language, an intermediate representation used by GCC to describe hardware operations before they are translated into machine code.
- producer-consumer relationship
- A dependency where one instruction (producer) generates a result that is used as an input by another instruction (consumer).
- pre-allocation destination overmatching
- A compiler optimization where the destination register of an instruction is speculated to be reused by a later instruction, even before exact register allocation is finalized. This allows for earlier instruction scheduling and potential fusion.
- subregister
- A portion of a larger register, treated as a distinct unit for certain operations.
- parameterized classifiers
- Helper functions or logic within the compiler that can identify instruction types based on various parameters, allowing for more flexible and reusable recognition rules.
- microarchitecture-specific constraints
- Rules and limitations imposed by the specific design of a processor's execution pipeline and functional units, which influence instruction scheduling and optimization.
- RISC-V
- An open-standard instruction set architecture (ISA) based on modularity, extensibility, and simplicity, gaining traction in embedded systems and high-performance computing.