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 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/fold-mem-offsets.cc b/gcc/fold-mem-offsets.cc
index feb2914c7b41..a3c67cf11e95 100644
--- a/gcc/fold-mem-offsets.cc
+++ b/gcc/fold-mem-offsets.cc
@@ -657,7 +657,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);
 }
-- 
2.34.1

Reply via email to