]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[4/6] fold-mem-offsets: Move RISC-V size-optimization workaround to the backend
authorPhilipp Tomsich <philipp.tomsich@vrull.eu>
Tue, 28 Apr 2026 17:22:35 +0000 (11:22 -0600)
committerJeff Law <jeffrey.law@oss.qualcomm.com>
Tue, 28 Apr 2026 17:22:35 +0000 (11:22 -0600)
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.

gcc/config/riscv/riscv.cc
gcc/fold-mem-offsets.cc

index 9ea00ed3d5fdc76b951353fc34dd22fac4002dc2..97272b4349a6d99844d71703f6a0374cbef4a794 100644 (file)
@@ -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;
 
index 17c92e104bd568f8da5b7a973b4550558f7eb85e..8480f134ed9040457cedc0d8700722592787feb6 100644 (file)
@@ -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);