https://gcc.gnu.org/g:9169639eaac152ca9d287819908c08b58e1ff508

commit 9169639eaac152ca9d287819908c08b58e1ff508
Author: Jeff Law <[email protected]>
Date:   Mon Feb 23 17:31:52 2026 -0700

    Add recursive call to back_propagate_equivalences
    
    This is enough to resolve pr90036 and one other.  I still need to put those
    tests into the testsuite.
    
    This does require adjusting one fortran test which tried to verify that
    DOM never finds anything in its expression equivalence table.  But with
    the new lookups, that's no longer a valid thing to test.  THe test does
    verify that DOM does not eliminate certain loads/stores that it might
    otherwise try to.

Diff:
---
 gcc/testsuite/gfortran.dg/unconstrained_commons.f |  1 -
 gcc/tree-ssa-dom.cc                               | 11 ++++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/unconstrained_commons.f 
b/gcc/testsuite/gfortran.dg/unconstrained_commons.f
index 28972b6d6b0e..1e830ca730f5 100644
--- a/gcc/testsuite/gfortran.dg/unconstrained_commons.f
+++ b/gcc/testsuite/gfortran.dg/unconstrained_commons.f
@@ -14,7 +14,6 @@
   10  CONTINUE
       RETURN
       END
-! { dg-final { scan-tree-dump-not "FIND" "dom2" } }
 ! We should retain both a read and write of mycommon.x.
 ! { dg-final { scan-tree-dump-times "  _\[0-9\]+ = 
mycommon\\.x\\\[_\[0-9\]+\\\];" 1 "dom2" } }
 ! { dg-final { scan-tree-dump-times "  mycommon\\.x\\\[j?_\[0-9\]+\\\] = 
_\[0-9\]+;" 1 "dom2" } }
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index dbe15e32094f..3c5172375c87 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -1171,12 +1171,17 @@ back_propagate_equivalences (tree lhs, edge e,
        record_equality (lhs2, res, const_and_copies);
 
       /* It may also be the case that the value is in the hash table.  So
-        try to look it up there too.  */
+        try to look it up there too.  But restrict ourselves to cases where
+        the hash lookup produced a constant rather than another SSA_NAME.
+        That avoids infinite recursion issues.  */
       res = avail_exprs_stack->lookup_avail_expr (use_stmt, false, false);
-      if (res && (TREE_CODE (res) == SSA_NAME || is_gimple_min_invariant 
(res)))
+      if (res && is_gimple_min_invariant (res))
        {
          record_equality (lhs2, res, const_and_copies);
-         class edge_info *edge_info = (class edge_info *) e->aux;
+
+         /* And that in turn may trigger further propagation opportunities.  */
+         back_propagate_equivalences (lhs2, e, avail_exprs_stack,
+                                      const_and_copies, domby);
        }
     }
 }

Reply via email to