https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101179

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

https://gcc.gnu.org/g:5b40e9d181bfe268ee9922c6af525bc5dab2604c

commit r17-3791-g5b40e9d181bfe268ee9922c6af525bc5dab2604c
Author: Daniel Barboza <[email protected]>
Date:   Thu Jul 30 13:51:21 2026 -0300

    forwprop: add simplify_phi_result_movdiv() [PR101179]

    This new forwprop step implements some of Richi's suggestions from v1 of
    this work [1] where he suggested to push things out of match.pd.

    The idea is to simplify DIV/MOD into RSHIFT/BIT_AND ops in which the
    divisor are pow2 positive integers in a PHI.  E.g.:

    - for TRUNC_MOD and FLOOR_MOD, if either "_y" is known positive or
      "_x" is used just in zero comparisons:

    phi_var = PHI <16,4>
    _x = _y % phi_var

    Can be turned into:

    phi_var = PHI <15,3>
    _x = _y & phi_var

    - for TRUNC_DIV, FLOOR_DIV and EXACT_DIV, if "_y" is a known positive:

    phi_var = PHI <16,4>
    _x = _y / phi_var

    Can be turned into:

    phi_var = PHI <4,2>
    _x = _y >> phi_var

    Most of 101179 use cases are solved by this change.  PHI with 2+ args
    are supported as long as every phi_arg meets the criteria.

    Boostrapped and regression tested with x86_64, aarch64 and riscv64.

    [1] https://gcc.gnu.org/pipermail/gcc-patches/2026-May/716303.html

            PR tree-optimization/101179

    gcc/ChangeLog:

            * tree-ssa-forwprop.cc (simplify_phi_result_movdiv): New
            forwprop step where MOD/DIV ops with pow2 divisors can be
            simplified to BIT_AND/RSHIFT.
            (pass_forwprop::execute): Call simplify_phi_result_movdiv.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/pr101179.c: New test.

Reply via email to