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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrea Pinski <[email protected]>:

https://gcc.gnu.org/g:44c89620f7390687a01045228d263845e6e311aa

commit r17-3822-g44c89620f7390687a01045228d263845e6e311aa
Author: Andrea Pinski <[email protected]>
Date:   Sat Aug 29 11:46:17 2026 -0700

    phiopt: Fix factor/merging out of calls [PR126977]

    Some builtins and some expressions can't be combined in some cases.
    An example is the crc builtins can't be factored out/commonialized if
    the 3rd argument is different as that would cause an error as the crc
    builtins require a constant there.  The same is true of some others
    like BIT_INSERT_EXPR and BIT_FIELD_REF which requires a constant.
    Right now there are 3 different locations which handle the same
    thing. This extracts all 3 different locations into one function,
    factor_operation_ok.
    And adds a few more restrictions that was not handled before:
    CRC, expect, object_size, clz, ctz (only internal function with 2
arguments),
    prefetch, and frame address.

    Note since the restriction on BIT_INSERT_EXPR is relaxed slightly,
    pr113609-2.c needs to be updated to allow for the better optimization
    that is happening now.

            PR tree-optimization/126977
    gcc/ChangeLog:

            * gimple-match-exports.cc (fn_arg_must_be_const_p): New function.
            (all_ssa_names_p): New function.
            (factor_operation_ok): New exported function.
            * gimple-match.h (factor_operation_ok): New declaration.
            * tree-if-conv.cc (factor_out_operators): Use factor_operation_ok.
            * tree-ssa-phiopt.cc (factor_out_conditional_operation): Use
            factor_operation_ok.
            * tree-ssa-tail-merge.cc (merge_stmts_p): Use factor_operation_ok
            instead of just looking at specific internal functions.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr113609-2.c: Update for factoring of
            BIT_INSERT_EXPR.
            * gcc.dg/torture/pr126977-1.c: New test.

    Signed-off-by: Andrea Pinski <[email protected]>
    Co-authored-by: Naveen <[email protected]>

Reply via email to