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

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

https://gcc.gnu.org/g:eb311f861255ae1fcaafa3454d4d1d6f1da07497

commit r17-4551-geb311f861255ae1fcaafa3454d4d1d6f1da07497
Author: liuhongt <[email protected]>
Date:   Tue Aug 4 01:55:18 2026 -0700

    tree-optimization/126486 - fold sign-changing conversions in IVOPTS

    r15-6657 canonicalized signed arithmetic to unsigned and exposed a
    17.5% code-size regression at -O2 in SPEC CPU2017 507.cactuBSSN_r.
    The resulting conversion chains hide common outer-loop IV terms from
    affine decomposition.

    Enable ranger during IVOPTS and pass the use statement to tree-affine.
    Use contextual ranges to remove value-preserving sign changes and fold
    modular arithmetic into exact arithmetic.  Keep candidate computations
    context-free because they may be emitted in the loop preheader.

    Ranger also derives n <= UINT_MAX - 4 after the preceding step-4 loop
    in pr19210-1.c exits, discharging the next loop niter assumption.  Adjust
    the diagnostic expectation.

    On ia32, the improved IV choice can spill a loop bound through a mask
    register while still reducing code size and hot-loop work.  Restrict the
    unrelated no-kmov check to non-ia32 targets.

    .i.e
    inv_expr 3:     ((unsigned long) k_41 * 8 + (unsigned long)\
    input_array_dims_28(D)) - (unsigned long) (int) ((unsigned int k_41 +\
    4294967295) * 8

    Can be simplified to

    (unsigned long) input_array_dims_28(D) + 8

    When ranger proves k_41 >= 1

    The fix slightly improves 507.cactuBSSN_r performance and improves
    548.exchange2_r by about 6% on Intel GNR, AMD Zen 5, and Arm Graviton
    5.

    gcc/ChangeLog:

            PR tree-optimization/126486
            * tree-affine.cc: Include vr-values.h.
            (aff_combination_convert): Accept and propagate range context.
            (expr_to_aff_combination): Likewise.  Fold sign-changing
conversions
            and negative unsigned offsets.
            (tree_to_aff_combination): Accept and propagate range context.
            * tree-affine.h (aff_combination_convert): Update declaration.
            (tree_to_aff_combination): Likewise.
            * tree-ssa-loop-ivopts.cc: Include gimple-range.h.
            (get_computation_aff_1): Pass the use statement.
            (tree_ssa_iv_optimize): Enable ranger.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/126486
            * gcc.dg/tree-ssa/pr126486.c: New test.
            * gcc.dg/tree-ssa/pr19210-1.c: Remove obsolete missed diagnostic.
            * gcc.target/i386/kortest_ccz-1.c: Restrict no-kmov scan to
non-ia32.

            Assisted-by: openai.gpt-5.6-sol xhigh <[email protected]>

Reply via email to