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

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

https://gcc.gnu.org/g:75433a625dcc714e11c84e6ec023b4959433ea10

commit r17-6768-g75433a625dcc714e11c84e6ec023b4959433ea10
Author: Frédéric Mahé <[email protected]>
Date:   Fri Nov 27 19:08:30 2026 -0700

    [PATCH v2] middle-end: Do not sink a scalar-result operation into
VEC_COND_EXPR arms [PR129083]

    fold_binary_op_with_conditional_arg sinks an operation into the arms
    of a VEC_COND_EXPR even when its result is scalar, such as the
    whole-vector comparison of an early-break exit test.  Each arm is then
    folded on its own, so with constant arms the comparison can fold to a
    wrong constant.  This miscompiles the libstdc++ tests
    23_containers/vector/bool/modifiers/assign/assign_range.cc and
    insert/append_range.cc on riscv64 with VLEN 256.

    The non-COND path of the function already punts when a vector operand
    has a scalar result; do the same for VEC_COND_EXPR.

    The bug was reduced with the help of Claude (Anthropic).

    ---
    Changes in v2 (thanks, Richard):
    - add the Bugzilla reference (PR middle-end/129083);
    - move the test to gcc.dg/vect/vect-pr129083.c, since vect_early_break
      only works in vect.exp; it now also calls check_vect ().

    Bootstrapped and regtested on riscv64-unknown-linux-gnu (native, SpacemiT
    K1, --with-arch=rv64gcv_zba_zbb_zbc_zbs_zicond_zfh_zvfh_zvl256b), C and
    C++, compared with an unpatched run of the same revision: no new
    failures.  The libstdc++ tests vector/bool/modifiers/assign/assign_range.cc
    and insert/append_range.cc now pass (they failed before).

    The new test, run in vect.exp on riscv64: FAIL (execution, also with
    -flto) without the fold-const.cc change, PASS with it.  On x86_64 (by
    hand, -msse4.1 as added by vect_early_break) it aborts without the
    change, also with GCC 15.2, and passes with it.

            PR middle-end/129083

    gcc/ChangeLog:

            * fold-const.cc (fold_binary_op_with_conditional_arg): Punt for a
            VEC_COND_EXPR operand when the result type is not a vector.

    gcc/testsuite/ChangeLog:

            * gcc.dg/vect/vect-pr129083.c: New test.

    Signed-off-by: Frédéric Mahé <[email protected]>

Reply via email to