Prevent size-growing complete loop unrolling at -O2.
RISC-V now avoids aggressive complete loop unrolling at -O2 unless explicitly requested.
This commit modifies the RISC-V backend’s default optimization behavior. While -O2 typically enables small-loop unrolling, this change prevents ‘complete unrolling’ that could lead to code size increases, unless the user explicitly requests it via flags. This aims to strike a better balance between performance and code size for typical -O2 compilations on RISC-V.
In Details
For the RISC-V target, the default options at -O2 level previously included enabling -funroll-loops, which could lead to size-growing complete unrolling. This patch introduces a riscv_override_options_after_change function and calls it via riscv_option_override and TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE. This mechanism now selectively disables complete unrolling unless explicitly enabled by the user, preventing unintended code bloat from -O2.
- Complete unrolling
- A loop optimization technique where all iterations of a loop are expanded into sequential code, eliminating loop overhead but potentially increasing code size.
- -O2
- A GCC optimization level that enables a wide range of optimizations aimed at improving speed without excessive compilation time or code size increase.
- -funroll-loops
- A GCC flag that instructs the compiler to perform loop unrolling.