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

--- 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:fc58b1fc537f0b8cad5762f70809678d22dd3c80

commit r17-3470-gfc58b1fc537f0b8cad5762f70809678d22dd3c80
Author: Tamar Christina <[email protected]>
Date:   Thu Aug 20 12:54:39 2026 +0100

    vect: fixup divmod pattern [PR126961]

    Running the pr104116 tests with SVE2 which implements IFN_DIV_POW2 results
in

    FAIL: gcc.dg/vect/pr104116-ceil-div-2.c execution test
    FAIL: gcc.dg/vect/pr104116-ceil-div-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-ceil-mod-2.c execution test
    FAIL: gcc.dg/vect/pr104116-ceil-mod-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-ceil-udiv-2.c execution test
    FAIL: gcc.dg/vect/pr104116-ceil-udiv-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-ceil-umod-2.c execution test
    FAIL: gcc.dg/vect/pr104116-ceil-umod-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-floor-div-2.c execution test
    FAIL: gcc.dg/vect/pr104116-floor-div-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-floor-mod-2.c execution test
    FAIL: gcc.dg/vect/pr104116-floor-mod-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-round-div-2.c execution test
    FAIL: gcc.dg/vect/pr104116-round-div-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-round-mod-2.c execution test
    FAIL: gcc.dg/vect/pr104116-round-mod-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-round-udiv-2.c execution test
    FAIL: gcc.dg/vect/pr104116-round-udiv-pow2.c execution test
    FAIL: gcc.dg/vect/pr104116-round-umod-2.c execution test
    FAIL: gcc.dg/vect/pr104116-round-umod-pow2.c execution test

    The first part is that add_code_for_floorceilround_divmod expects that the
6th
    parameter be the remainder.  This is passed correctly for most uses except
for
    one where instead the shifted quotient is passed instead which causes a
    miscompile.

    Secondly IFN_DIV_POW2 is defined for only signed types.

    DEF_INTERNAL_OPTAB_FN (DIV_POW2, ECF_CONST | ECF_NOTHROW, sdiv_pow2,
binary)

    and the documentation says

    @itemx @samp{sdiv_pow2@var{m}3}
    Signed division by power-of-2 immediate. Equivalent to:

    However the code does not actually check that the type is signed.
    So we end up using the IFN for unsigned division as well resulting in the
    failures for the unsigned testcases.

    gcc/ChangeLog:

            PR tree-optimization/126961
            * tree-vect-patterns.cc (vect_recog_divmod_pattern): Fix remainder
use
            and add signedness check.

Reply via email to