https://gcc.gnu.org/g:4287deacbbee32d165d98e47dd01a60069cdcedb

commit r16-8034-g4287deacbbee32d165d98e47dd01a60069cdcedb
Author: Philipp Tomsich <[email protected]>
Date:   Mon Feb 23 20:22:03 2026 +0100

    fold-mem-offsets: Clarify why do_analysis pre-marks the memory insn
    
    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.

Diff:
---
 gcc/fold-mem-offsets.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/fold-mem-offsets.cc b/gcc/fold-mem-offsets.cc
index 1cd2dc036c2f..17c92e104bd5 100644
--- a/gcc/fold-mem-offsets.cc
+++ b/gcc/fold-mem-offsets.cc
@@ -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);
 }

Reply via email to