From: Philipp Tomsich Date: Tue, 28 Apr 2026 17:22:35 +0000 (-0600) Subject: [4/6] fold-mem-offsets: Move RISC-V size-optimization workaround to the backend X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=03fcac336e04ba2cd57495a47534accc145e160e;p=thirdparty%2Fgcc.git [4/6] fold-mem-offsets: Move RISC-V size-optimization workaround to the backend The fold-mem-offsets pass contained a target-specific workaround that skipped basic blocks optimized for size, to avoid conflicting with RISC-V's shorten-memrefs pass. This penalized all targets. Move the workaround to the RISC-V backend by disabling fold-mem-offsets via SET_OPTION_IF_UNSET in riscv_option_override when optimizing for size with compressed instructions enabled (the same condition that gates the shorten-memrefs pass). This preserves the RISC-V behavior while allowing other targets to fold offsets in size-optimized blocks. gcc/ChangeLog: * fold-mem-offsets.cc (pass_fold_mem_offsets::execute): Remove optimize_bb_for_size_p check. * config/riscv/riscv.cc (riscv_option_override): Disable flag_fold_mem_offsets when optimizing for size with compressed instructions. --- diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 9ea00ed3d5f..97272b4349a 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -12558,6 +12558,12 @@ riscv_option_override (void) param_cycle_accurate_model, 0); + /* Disable fold-mem-offsets when optimizing for size with compressed + instructions, as it conflicts with the shorten-memrefs pass. */ + if (optimize_size && (TARGET_RVC || TARGET_ZCA)) + SET_OPTION_IF_UNSET (&global_options, &global_options_set, + flag_fold_mem_offsets, 0); + /* Function to allocate machine-dependent function status. */ init_machine_status = &riscv_init_machine_status; diff --git a/gcc/fold-mem-offsets.cc b/gcc/fold-mem-offsets.cc index 17c92e104bd..8480f134ed9 100644 --- a/gcc/fold-mem-offsets.cc +++ b/gcc/fold-mem-offsets.cc @@ -878,12 +878,6 @@ pass_fold_mem_offsets::execute (function *fn) rtx_insn *insn; FOR_ALL_BB_FN (bb, fn) { - /* There is a conflict between this pass and RISCV's shorten-memrefs - pass. For now disable folding if optimizing for size because - otherwise this cancels the effects of shorten-memrefs. */ - if (optimize_bb_for_size_p (bb)) - continue; - fold_info_map fold_info; bitmap_clear (&can_fold_insns);