]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-mem-offsets: Clarify why do_analysis pre-marks the memory insn
authorPhilipp Tomsich <philipp.tomsich@vrull.eu>
Mon, 23 Feb 2026 19:22:03 +0000 (20:22 +0100)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Thu, 12 Mar 2026 10:22:38 +0000 (11:22 +0100)
The bitmap_set_bit call before fold_offsets in do_analysis is
intentional: fold_offsets requires all uses of a definition to already
be in can_fold_insns before it will mark the definition as foldable.
Pre-marking the memory instruction (which is the root use) is necessary
for its address definitions to pass this check during the DFS.

Replace the generic comment with one that explains this dependency.

gcc/ChangeLog:

* fold-mem-offsets.cc (do_analysis): Revise comment.

gcc/fold-mem-offsets.cc

index 1cd2dc036c2ff7bcdee3b25df82353d1536da38e..17c92e104bd568f8da5b7a973b4550558f7eb85e 100644 (file)
@@ -653,7 +653,10 @@ do_analysis (rtx_insn *insn)
       print_rtl_single (dump_file, insn);
     }
 
-  /* Analyse folding opportunities for this memory instruction.  */
+  /* Mark this memory instruction as foldable before the DFS so that its
+     address definitions can see it in can_fold_insns during analysis.
+     This is required because fold_offsets checks that all uses of a
+     definition are in can_fold_insns before marking the definition.  */
   bitmap_set_bit (&can_fold_insns, INSN_UID (insn));
   fold_offsets (insn, reg, true, NULL);
 }