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

--- Comment #3 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:3f6fb81133dfa2b8f843b328fd6b697534e7b3fe

commit r17-4706-g3f6fb81133dfa2b8f843b328fd6b697534e7b3fe
Author: Stian Halseth <[email protected]>
Date:   Sun Sep 27 21:51:28 2026 -0600

    [PATCH v3] ifcvt: Do not clobber a live condition-code register in
find_cond_trap [PR127578]

    find_cond_trap emits the sequence from gen_cond_trap before cond_earliest.
    On SPARC that sequence is a comparison followed by a trap on the condition
    codes, but the branch it replaces need not read them: a cbcond tests
    general registers, so a condition code set earlier can be live across
    TEST_BB and read by a later branch, which then tests the wrong value.

    The fix for PR126501 added noce_clobbers_live_cc_p for the same problem in
    the noce paths.  Use it here too.

    On sparc64 with -mcbcond this miscompiles a switch over a sparse enum whose
    default arm is unreachable, which is why LLVM 23 does not build there.

    Bootstrapped on sparc64-unknown-linux-gnu.  The C and C++ testsuites,
    run against an otherwise identical unpatched tree, change only in the
    new test, which fails without the patch and passes with it.

    ---
    Changes since v2: document cbcond_hw in doc/sourcebuild.texi.
    Changes since v1: reuse noce_clobbers_live_cc_p, the check that
    end_ifcvt_sequence already makes, instead of adding a new liveness check.

            PR rtl-optimization/127578
    gcc/ChangeLog:

            * doc/sourcebuild.texi (cbcond_hw): Document.
            * ifcvt.cc (find_cond_trap): Reject a sequence that clobbers a
            condition-code register live out of TEST_BB.

    gcc/testsuite/ChangeLog:

            * lib/target-supports.exp (check_effective_target_cbcond_hw): New.
            * gcc.target/sparc/cbcond-trap-1.c: New test.

Reply via email to