https://gcc.gnu.org/g:a316d2f2c5954eb05ba68179efed99039a8bc088

commit a316d2f2c5954eb05ba68179efed99039a8bc088
Author: Jeff Law <[email protected]>
Date:   Sun Feb 22 09:38:24 2026 -0700

    Derive more equivalenecs
    
    When deriving equivalences, if we have IOR where one operand is zero,
    then that creates a simple equivalence between the result and the
    other operand.

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

diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index 86da83902951..67d1592b9ba4 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -189,7 +189,26 @@ edge_info::derive_equivalences (tree name, tree value, int 
recursion_limit)
              value = build_zero_cst (TREE_TYPE (rhs2));
              derive_equivalences (rhs2, value, recursion_limit - 1);
            }
-         break;
+         else
+           {
+             /* If an operand is zero, then the other operand must have
+                the same value as the result.  */
+             tree rhs1 = gimple_assign_rhs1 (def_stmt);
+             tree rhs2 = gimple_assign_rhs2 (def_stmt);
+
+             if (integer_zerop (rhs1)
+                 || (TREE_CODE (rhs1) == SSA_NAME
+                     && SSA_NAME_VALUE (rhs1)
+                     && integer_zerop (SSA_NAME_VALUE (rhs1))))
+               derive_equivalences (rhs2, value, recursion_limit - 1);
+
+             if (integer_zerop (rhs2)
+                 || (TREE_CODE (rhs2) == SSA_NAME
+                     && SSA_NAME_VALUE (rhs2)
+                     && integer_zerop (SSA_NAME_VALUE (rhs2))))
+               derive_equivalences (rhs1, value, recursion_limit - 1);
+           }
+       break;
 
        /* If the result of an AND is nonzero, then its operands are, too.  */
        case BIT_AND_EXPR:

Reply via email to