https://gcc.gnu.org/g:0f9968ce843fb2c729a8baefc1becaa0074778a3

commit 0f9968ce843fb2c729a8baefc1becaa0074778a3
Author: Jeff Law <[email protected]>
Date:   Sun Feb 22 09:41:54 2026 -0700

    Do more back-propagation of equivalences.
    
    When we encounter a COND_EXPR with an equality test during
    creation of temporary equivalences, try to back-propagate for
    the SSA_NAME source operand.

Diff:
---
 gcc/tree-ssa-dom.cc | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index 67d1592b9ba4..dbe15e32094f 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -1202,7 +1202,25 @@ record_temporary_equivalences (edge e,
       /* If we have 0 = COND or 1 = COND equivalences, record them
         into our expression hash tables.  */
       for (i = 0; edge_info->cond_equivalences.iterate (i, &eq); ++i)
-       avail_exprs_stack->record_cond (eq);
+       {
+         avail_exprs_stack->record_cond (eq);
+
+         /* This is not a simple equivalence, but may still enable
+            discovery of other equivalences.  This is fairly narrowly
+            implemented and can likely be generalized further.
+
+            Essentially we're looking for [0/1] = A cond [0/1] and try
+            to derive equivalences at use points of A.  */
+            if ((integer_zerop (eq->value) || integer_onep (eq->value))
+                && eq->cond.kind == EXPR_BINARY
+                && (eq->cond.ops.binary.op == EQ_EXPR
+                    || eq->cond.ops.binary.op == NE_EXPR)
+                && TREE_CODE (eq->cond.ops.binary.opnd0) == SSA_NAME
+                && TREE_CODE (eq->cond.ops.binary.opnd1) == INTEGER_CST)
+               back_propagate_equivalences (eq->cond.ops.binary.opnd0, e,
+                                            avail_exprs_stack,
+                                            const_and_copies, blocks_on_stack);
+       }
 
       edge_info::equiv_pair *seq;
       for (i = 0; edge_info->simple_equivalences.iterate (i, &seq); ++i)

Reply via email to