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

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

https://gcc.gnu.org/g:9b007ab575a4a71f4b5458fc214eee87f31d6a21

commit r17-6341-g9b007ab575a4a71f4b5458fc214eee87f31d6a21
Author: Kyrylo Tkachov <[email protected]>
Date:   Wed Nov 11 05:12:10 2026 -0800

    aarch64: Do vaba accumulation in unsigned type [PR128556]

    vaba_<s> intrinsics are folded to ABD followed by a PLUS_EXPR on the
    accumulator.  For signed element types the PLUS_EXPR is in the signed
    type, which has undefined overflow although the intrinsic wraps.  Later
    folds then assume no overflow.  For example vshr_n_s8 (vaba_s8 (a, x, y),
1)
    becomes an AVG_FLOOR and returns a value that is not truncated to 8 bits.

    Before:
      _2 = .ABD (x, y);
      _1 = acc + _2;           (signed, UB on overflow)

    After:
      _2 = .ABD (x, y);
      _3 = VIEW_CONVERT_EXPR<uvec> (acc);
      _4 = VIEW_CONVERT_EXPR<uvec> (_2);
      _5 = _3 + _4;
      _1 = VIEW_CONVERT_EXPR<svec> (_5);

    This is the same approach gimple_arith_base::fold uses for vadd.  The
    saba instruction is still generated for the plain accumulate case.

    Bootstrapped and tested on aarch64-none-linux-gnu.

    gcc/ChangeLog:

            PR target/128556
            * config/aarch64/aarch64-neon-builtins-base.cc
            (gimple_abs_diff::fold): Perform the accumulation in the
            unsigned type.

    gcc/testsuite/ChangeLog:

            PR target/128556
            * gcc.target/aarch64/simd/pr128556.c: New test.

    Signed-off-by: Kyrylo Tkachov <[email protected]>

Reply via email to