[Bug tree-optimization/107090] [aarch64] sequence logic should be combined with mul and umulh

"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107090

--- Comment #25 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Philipp Tomsich <[email protected]>:

https://gcc.gnu.org/g:0502e6b1e7be3d3fe00727e2936d3c3a03537c4e

commit r17-3442-g0502e6b1e7be3d3fe00727e2936d3c3a03537c4e
Author: Konstantinos Eleftheriou <[email protected]>
Date:   Thu Jul 9 02:22:29 2026 -0700

    match.pd, forwprop: Recognize long-multiply carries written as 2-arg PHI

    Hand-written long-multiply code commonly writes the carry as a 2-arg
    PHI

        if (mul_hilo0 > low_sum)
          result = result_partial + (1ULL << N);
        else
          result = result_partial;

    with no top-level + at the join for the chain walk to start from.

    Add a PHI-driven entry: cond_carry_add / cond_carry_add_neg match
    PHI<base + pow2, base> guarded by an unsigned compare on (a, sum) in
    either polarity; the captured sum is classified into a carry summand,
    base is linearized for the remaining summands, and on a match the
    2N-bit multiply is emitted with the PHI result as its LHS.  Only
    HIGH_PART rows are reachable; LOW_PART rows are BIT_IOR chains and
    never produce a carry PHI.

            PR tree-optimization/107090

    gcc/ChangeLog:

            * match.pd: Add cond_carry_add and cond_carry_add_neg match
            recognizers for the 2-arg PHI form PHI<base + pow2, base>,
            one per gcond polarity.
            * tree-ssa-forwprop.cc (gimple_cond_carry_add): Declare.
            (gimple_cond_carry_add_neg): Likewise.
            (long_mul_check_low_plus_defer): Note that the PHI entry commits
            only to HIGH_PART rows.
            (long_mul_classify_match): Take the candidate statement for the
            per-row checks.
            (long_mul_classify_chain): Take an optional pre-classified extra
            summand, for the carry the PHI entry synthesizes.
            (match_long_mul): Adjust.
            (match_long_mul_phi): New PHI-driven entry; recognizes a
            cond_carry_add(_neg) PHI and folds the long-multiply
            when the rest of the high-part chain matches.
            (pass_forwprop::execute): Call match_long_mul_phi on each
            PHI in the degenerate-PHI walk.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/long-mul-carry.c: Add PHI-form CARRY_LOW_SUM,
            CARRY_CROSS_SUM, and negated-branch compile variants; split the
            forwprop1 high-part fold count into 10 on int128 and 8 on !int128.
            * gcc.dg/tree-ssa/long-mul-two-carry.c: Add the
            mulh_two_carry_low_phi function and its forwprop3 high-part
            (carry PHI) fold scan.
            * gcc.dg/tree-ssa/long-mul-boundary-64.c: New test.
            * gcc.dg/tree-ssa/long-mul-boundary.c: New test.
            * gcc.dg/tree-ssa/long-mul-partial.c: New test.

    Co-authored-by: Philipp Tomsich <[email protected]>
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.