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

commit r17-4939-geeae43a4c615c08ce13ffbd8e882fcf1871a996d
Author: Aldy Hernandez <[email protected]>
Date:   Tue Oct 6 05:36:30 2026 +0000

    DOM: a constant is never the first operand
    
    Clean up some places where we're scanning for constants on the LHS of
    a binary operation.  This never gets tickled as gimple keeps constants
    on the RHS.  Don't touch the MINUS_EXPR case, as subtraction is not
    commutative.
    
    Likewise for record_edge_info where we have an arm for a conditional
    with the constant on the left, with a comment saying copy propagation
    can produce one.  However, fold_stmt canonicalizes the operand order
    of a GIMPLE_COND, so by the time record_edge_info gets it, the
    constant is on the right.
    
    Assembly is identical with and without this change over a corpus of
    .ii files from a stage1 bootstrap and over the LAPACK Fortran sources,
    and gcov shows the removed code never executes over those files nor
    the C, C++ and Fortran testsuites.
    
    Tested on ppc64le Linux.
    
    gcc/ChangeLog:
    
            * tree-ssa-dom.cc (edge_info::derive_equivalences): Remove the
            constant-first arms of the PLUS_EXPR and EQ_EXPR cases.
            (record_edge_info): Remove the arm for a constant first operand.

Diff:
---
 gcc/tree-ssa-dom.cc | 48 +++++++-----------------------------------------
 1 file changed, 7 insertions(+), 41 deletions(-)

diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index 1470d65f4e3c..26c1d8dc1207 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -237,16 +237,10 @@ edge_info::derive_equivalences (tree name, tree value, 
int recursion_limit)
            tree rhs1 = gimple_assign_rhs1 (def_stmt);
            tree rhs2 = gimple_assign_rhs2 (def_stmt);
 
-           /* If either argument is a constant, then we can compute
-              a constant value for the nonconstant argument.  */
-           if (TREE_CODE (rhs1) == INTEGER_CST
-               && TREE_CODE (rhs2) == SSA_NAME)
-             derive_equivalences (rhs2,
-                                  fold_binary (MINUS_EXPR, TREE_TYPE (rhs1),
-                                               value, rhs1),
-                                  recursion_limit - 1);
-           else if (TREE_CODE (rhs2) == INTEGER_CST
-                    && TREE_CODE (rhs1) == SSA_NAME)
+           /* If the second argument is a constant, then we can compute
+              a constant value for the first one.  */
+           if (TREE_CODE (rhs2) == INTEGER_CST
+               && TREE_CODE (rhs1) == SSA_NAME)
              derive_equivalences (rhs1,
                                   fold_binary (MINUS_EXPR, TREE_TYPE (rhs1),
                                                value, rhs2),
@@ -296,14 +290,12 @@ edge_info::derive_equivalences (tree name, tree value, 
int recursion_limit)
                tree rhs1 = gimple_assign_rhs1 (def_stmt);
                tree rhs2 = gimple_assign_rhs2 (def_stmt);
 
-               /* If either argument is a constant, then record the
-                  other argument as being the same as that constant.
+               /* If the second argument is a constant, then record the
+                  first argument as being the same as that constant.
 
                   If neither operand is a constant, then we have a
                   conditional name == name equivalence.  */
-               if (TREE_CODE (rhs1) == INTEGER_CST)
-                 derive_equivalences (rhs2, rhs1, recursion_limit - 1);
-               else if (TREE_CODE (rhs2) == INTEGER_CST)
+               if (TREE_CODE (rhs2) == INTEGER_CST)
                  derive_equivalences (rhs1, rhs2, recursion_limit - 1);
              }
            else
@@ -538,32 +530,6 @@ record_edge_info (basic_block bb)
                                                   ? false_val : true_val));
                 }
             }
-         /* This can show up in the IL as a result of copy propagation
-            it will eventually be canonicalized, but we have to cope
-            with this case within the pass.  */
-          else if (is_gimple_min_invariant (op0)
-                   && TREE_CODE (op1) == SSA_NAME)
-            {
-              tree cond = build2 (code, boolean_type_node, op0, op1);
-              tree inverted = invert_truthvalue_loc (loc, cond);
-             bool can_infer_simple_equiv
-               = !(HONOR_SIGNED_ZEROS (op0) && real_maybe_zerop (op0))
-                 && !DECIMAL_FLOAT_MODE_P (element_mode (TREE_TYPE (op0)));
-             class edge_info *edge_info;
-
-             edge_info = new class edge_info (true_edge);
-              record_conditions (&edge_info->cond_equivalences, cond, 
inverted);
-
-              if (can_infer_simple_equiv && code == EQ_EXPR)
-               edge_info->record_simple_equiv (op1, op0);
-
-             edge_info = new class edge_info (false_edge);
-              record_conditions (&edge_info->cond_equivalences, inverted, 
cond);
-
-              if (can_infer_simple_equiv && TREE_CODE (inverted) == EQ_EXPR)
-               edge_info->record_simple_equiv (op1, op0);
-            }
-
           else if (TREE_CODE (op0) == SSA_NAME
                    && (TREE_CODE (op1) == SSA_NAME
                        || is_gimple_min_invariant (op1)))

Reply via email to