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.
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;
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);