https://gcc.gnu.org/g:4fc22cd1159e19a5b6830c8e3c70f7b1f44748fc

commit r17-4934-g4fc22cd1159e19a5b6830c8e3c70f7b1f44748fc
Author: Kyrylo Tkachov <[email protected]>
Date:   Mon Oct 5 22:08:01 2026 +0200

    genmatch: Relax overlap_node barrier for GIMPLE/GENERIC pairs
    
    nodes_overlap_p returns true for any two DT_OPERAND nodes whose
    operand cases overlap.  decision_tree::find_node uses this to set
    overlap_node, which prevents a later node from merging into an earlier
    equal sibling across the blocking node.
    
    Of the 163 barrier refusals on trunk, 135 (83%) are between the GIMPLE
    form and the GENERIC form that lower_cond gives every COND_EXPR
    condition.  gen_kids_1 dispatches the GIMPLE form under the SSA_NAME
    case and the GENERIC form by the operand's own TREE_CODE.  An input
    cannot satisfy both dispatch conditions simultaneously, so these 135
    refusals protect no ordering-sensitive case.
    
    Add a check in nodes_overlap_p: return false when the two expressions
    differ in is_generic.  This eliminates the spurious GIMPLE/GENERIC
    overlap refusals while keeping every DT_MATCH and overlapping
    operator-set refusal.  The 7 remaining order-sensitive pattern pairs
    all require degenerate inputs that other patterns fold first, and both
    of the patterns in each pair produce the same result value.
    
    On aarch64 at ten GIMPLE parts, GIMPLE lines fall by about 0.6%.
    GENERIC output is unchanged.
    
    Bootstrapped and tested on aarch64-none-linux-gnu.
    Ok for trunk?
    Thanks,
    Kyrill
    
    gcc/ChangeLog:
    
            * genmatch.cc (nodes_overlap_p): Return false when the two
            expressions have different is_generic, as they cannot match the
            same input.
    
    Signed-off-by: Kyrylo Tkachov <[email protected]>

Diff:
---
 gcc/genmatch.cc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index da80a2c4778d..249741e77cc6 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -2839,8 +2839,16 @@ nodes_overlap_p (dt_node *n1, dt_node *n2)
   if (n1->type == dt_node::DT_MATCH || n2->type == dt_node::DT_MATCH)
     return true;
 
-  return operand_cases_overlap_p (as_a <dt_operand *> (n1)->op,
-                                 as_a <dt_operand *> (n2)->op);
+  operand *op1 = as_a <dt_operand *> (n1)->op;
+  operand *op2 = as_a <dt_operand *> (n2)->op;
+  /* A GIMPLE expression and a GENERIC expression are dispatched through
+     separate paths (SSA_NAME case vs. operand TREE_CODE) and cannot
+     match the same input.  */
+  expr *e1 = op1 ? dyn_cast <expr *> (op1) : NULL;
+  expr *e2 = op2 ? dyn_cast <expr *> (op2) : NULL;
+  if (e1 && e2 && e1->is_generic != e2->is_generic)
+    return false;
+  return operand_cases_overlap_p (op1, op2);
 }
 
 /* Search OPS for a decision tree node like P and return it if found.  */

Reply via email to