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

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

https://gcc.gnu.org/g:2415f291466dc93182b64e6f069dd0015862e70f

commit r17-1453-g2415f291466dc93182b64e6f069dd0015862e70f
Author: Ciprian Arbone <[email protected]>
Date:   Tue Jun 9 16:31:11 2026 +0100

    ARM: Fix broken Thumb1 CBZ cc tracking [PR124077]

    thumb1_cbz uses operands[2], both when checking if it can reuse the
    previously set condition code, and when recording the operands that set
    the current condition code. operands[2] for this pattern is the target
    label of the jump though, and not the intended second operand of the
    comparison operator.

    As the label is unlikely to end up as operands[2], the condition code
    reuse logic doesn't kick in and causes the redundant CMP instruction
    described in PR124077. In addition, thumb1_final_prescan_insn also
    doesn't treat thumb1_cbz as a cbranch and ends up resetting condition
    code tracking state.

    Fix by replacing operands[2] with the actual second operand of the
    pattern i.e const0_rtx. Also treat thumb1_cbz the same as
    cbranchsi4_insn in thumb1_final_prescan_insn and let it track condition
    code state itself.

    gcc/ChangeLog:

            PR target/124077
            * config/arm/arm.cc (thumb1_final_prescan_insn): Also skip
            condition code update for thumb1_cbz instructions.
            * config/arm/thumb1.md (thumb1_cbz): Use const0_rtx as the
            recorded cc_op1 instead of operands[2].

    gcc/testsuite/ChangeLog:

            PR target/124077
            * gcc.target/arm/pr124077.c: New test.

    Co-authored-by: Senthil Kumar Selvaraj <[email protected]>

Reply via email to