RISC-V block move optimization improves dead code elimination
Optimizes RISC-V block moves to enable better dead code elimination.
This commit refactors how RISC-V handles block moves, particularly when a copied word is immediately overwritten by a subsequent store. Previously, the expansion deferred trailing whole words, causing the RTL Dead Store Elimination (DSE) pass to fail to prove the load was dead, resulting in unnecessary dead load and store instructions. By keeping the trailing word within the block move group, all loads precede all stores, allowing DSE to correctly identify and remove the dead code.
In Details
The riscv_block_move_straight function in RISC-V string operations was adjusted to keep trailing whole words within the block move RTL group, rather than deferring them. This change ensures that all loads associated with the block move occur before any subsequent stores that might overwrite the data. This ordering enables the RTL Dead Store Elimination (DSE) pass to more effectively prove the deadness of load-store pairs that are immediately overwritten, thus removing redundant instructions.
- RISC-V
- An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computer principles. GCC supports various RISC-V configurations.
- block move
- An operation that copies a contiguous block of memory from a source location to a destination location. In GCC, these are often implemented using specific library functions or optimized sequences of load and store instructions.
- RTL
- Register Transfer Language, an intermediate representation used within GCC to describe operations at a lower level than the GIMPLE or GENERIC forms, closer to machine code.
- Dead Store Elimination (DSE)
- An optimization pass in compilers that removes store operations whose results are never subsequently read.
- overwritten word
- A section of memory that is read by a load instruction and then subsequently written to by a store instruction within the same code sequence, potentially making the original load's result unnecessary.