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

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

https://gcc.gnu.org/g:22f3ee9a8153d4073befa55275a515b195cced85

commit r17-6169-g22f3ee9a8153d4073befa55275a515b195cced85
Author: Tamar Christina <[email protected]>
Date:   Thu Nov 12 12:50:30 2026 +0000

    AArch64: fix cbranch SVE fall-back pattern [PR128665]

    The following testcase

    const double a[] = {0, 1, 2, 3, 4, 5};
    __attribute__((noipa))
    int f(double x)
    {
        int i = 0;
    #pragma GCC unroll 0
        while (i < 6 && a[i] <= x)
            ++i;
        return i;
    }
    int main(void)
    {
        int result = f(2.0);
        return result != 3;
    }

    when compiled with -O3 -fno-trapping-math -march=armv8-a+sve

    generates incorrect code:

    f:
            ptrue   p15.b, vl16
            ptrue   p7.b, all
            dup     v30.2d, v0.d[0]
            adrp    x2, .LANCHOR0
            add     x1, x2, :lo12:.LANCHOR0
            mov     w0, 0
    .L5:
            ldr     q31, [x1]
            add     x1, x1, 16
            fcmle   p14.d, p7/z, z31.d, z30.d
            bics    p14.b, p15/z, p7.b, p14.b
            b.any   .L10
            add     w0, w0, 2
            cmp     w0, 6
            bne     .L5
            ret

    with this patch the mask is corrected to

    f:
            ptrue   p15.d, vl2
            ptrue   p7.b, all
            dup     v30.2d, v0.d[0]
            adrp    x2, .LANCHOR0
            add     x1, x2, :lo12:.LANCHOR0
            mov     w0, 0
    .L5:
            ldr     q31, [x1]
            add     x1, x1, 16
            fcmle   p14.d, p7/z, z31.d, z30.d
            bics    p14.b, p15/z, p7.b, p14.b
            b.any   .L10
            add     w0, w0, 2
            cmp     w0, 6
            bne     .L5
            ret

    gcc/ChangeLog:

            PR target/128665
            * config/aarch64/aarch64-simd.md (vec_cbranch_any,
            vec_cbranch_all): Correct mask.

    gcc/testsuite/ChangeLog:

            PR target/128665
            * gcc.target/aarch64/sve/vect-revectorize-ptest-1.c: New test.

Reply via email to