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

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

https://gcc.gnu.org/g:5106ae4d86572d74c19ab13c8faf17e4debccace

commit r17-7002-g5106ae4d86572d74c19ab13c8faf17e4debccace
Author: Robin Dapp <[email protected]>
Date:   Mon Nov 30 22:09:27 2026 +0100

    scev: Sign extend in derive_simple_iv_with_niters. [PR128519]

    My refactor in derive_simple_iv_with_niters missed an extension.
    We have a chrec {1, +, 65535} (actually -1 but represented in unsigned
    short).  The old code converted the step to unsigned int and built an
    evolution in unsigned int as well but with the step zero extended like
    1, 65536, 131071, ... valid for the bounds (65535 - 1) / 65535 = 0.

    Actually, the bounds was always just 0 or 1 when it could have been more
    reasonable if we computed the bound as {1, +, "-1" = 0xffffffff} right
    away.  That's what my refactor did by accident.

    So the problem is that evolution and bound disagreed after the refactor.
    We could either pass get_niter_type_bound the zero-extended STEP or
    sign-extend STEP according to its sign bit, similar to how
    get_niter_type_bound handles it.  I went for the latter.

    Bootstrapped and regtested on x86, power10, and aarch64.
    Regtested on riscv64.

            PR tree-optimization/128519

    gcc/ChangeLog:

            * tree-scalar-evolution.cc (derive_simple_iv_with_niters):
            Extend step according to the inner type.

    gcc/testsuite/ChangeLog:

            * gcc.dg/pr128519.c: New test.

Reply via email to