[gcc r17-3534] match/forwprop: Simplify handling of cond_carry_add

Andrea Pinski via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:dc16f9ae5101be400b63d2bea5cbdab3fe4becfe

commit r17-3534-gdc16f9ae5101be400b63d2bea5cbdab3fe4becfe
Author: Andrea Pinski <[email protected]>
Date:   Fri Aug 21 18:58:56 2026 -0700

    match/forwprop: Simplify handling of cond_carry_add
    
    So right there are two match patterns; one that handles
    tree true edge is the addition and one where the false edge is
    the addition.  But there is no reason why there can't be one
    match pattern which handles both of them. The forwprop code
    does not take care which edge is which. So let's merge them
    into one match pattern called cond_carry_add.
    This should have a small compile time (and memory usage due to
    creating a tree in the match due to cond^ handling) improvement
    as transversing the phi/cond only happens once.
    
    Pushed as obvious after a Bootstrapped/test on x86_64-linux-gnu.
    
    gcc/ChangeLog:
    
            * match.pd (cond_carry_add_neg): Rename to
            cond_carry_add.
            * tree-ssa-forwprop.cc (gimple_cond_carry_add_neg): Remove.
            (match_long_mul_phi): Don't call gimple_cond_carry_add_neg.
    
    Signed-off-by: Andrea Pinski <[email protected]>

Diff:
---
 gcc/match.pd             | 16 +++++++---------
 gcc/tree-ssa-forwprop.cc |  9 ++-------
 2 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 1f031e93a7ff..77e1c6cf61c5 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6839,20 +6839,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    guarded by an unsigned compare on (@0, @1).  @1 is captured without
    further structure; the long-mul fold in tree-ssa-forwprop.cc
    classifies it to drive a PHI-form carry summand.  The consumer
-   treats the carry as strict @0 > @1, so each polarity's compare
-   must encode that same condition:
-     cond_carry_add:     true edge selects (base + pow2), so the
-			 compare itself must be @0 > @1.
-     cond_carry_add_neg: true edge selects base, so the compare's
-			 negation must be @0 > @1, i.e. the
-			 compare itself must be @0 <= @1.
-   Matches the 2-arg PHI form via cond^.  */
+   treats the carry as strict @0 > @1, compares must encode that
+   same condition:
+     When the true edge selects (base + pow2), the
+       compare itself must be @0 > @1.
+     When the false edge selects (base + pow2), the
+       compare itself must be @0 <= @1 or rather the invese of @0 > @1.  */
 (if (INTEGRAL_TYPE_P (type)
      && TYPE_UNSIGNED (type)
      && type_has_mode_precision_p (type))
  (match (cond_carry_add @0 @1 @2 @3)
   (cond^ (gt:c @0 @1) (plus @2 integer_pow2p@3) @2))
- (match (cond_carry_add_neg @0 @1 @2 @3)
+ (match (cond_carry_add @0 @1 @2 @3)
   (cond^ (le:c @0 @1) @2 (plus @2 integer_pow2p@3))))
 
 /* (a > 1) ? 0 : (cast)a is the same as (cast)(a == 1)
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 475e49cea6d4..34acbcf033ee 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3614,13 +3614,9 @@ simplify_count_zeroes (gimple_stmt_iterator *gsi)
    up in a table.  On a hit, three cross-summand consistency checks
    decide whether the wide multiply is emitted.  */
 
-/* Match.pd recognizers for the conditional carry-add pattern.  The
-   two names split the gcond polarity: cond_carry_add matches when
-   the true edge selects (base + pow2), cond_carry_add_neg when the
-   true edge selects base.  */
+/* Match.pd recognizers for the conditional carry-add pattern. */
 
 extern bool gimple_cond_carry_add (tree, tree *, tree (*)(tree));
-extern bool gimple_cond_carry_add_neg (tree, tree *, tree (*)(tree));
 
 /* Match.pd functions to match long multiplication.  */
 
@@ -4689,8 +4685,7 @@ match_long_mul_phi (gphi *phi)
     return false;
 
   tree cca_ops[4];
-  if (!gimple_cond_carry_add (phi_res, cca_ops, NULL)
-      && !gimple_cond_carry_add_neg (phi_res, cca_ops, NULL))
+  if (!gimple_cond_carry_add (phi_res, cca_ops, NULL))
     return false;
   tree cmp_lhs = cca_ops[0];
   tree sum = cca_ops[1];
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.