https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120372
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>: https://gcc.gnu.org/g:bb7b6d9ad7f89ebc68c9d1eff16bec95f6e81cd9 commit r16-823-gbb7b6d9ad7f89ebc68c9d1eff16bec95f6e81cd9 Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Tue May 20 15:10:15 2025 -0700 aarch64: Improve rtx_cost for constants in COMPARE [PR120372] The middle-end uses rtx_cost on constants with the outer of being COMPARE to find out the cost of a constant formation for a comparison instruction. So for aarch64 backend, we would just return the cost of constant formation in general. We can improve this by seeing if the outer is COMPARE and if the constant fits the constraints of the cmp instruction just set the costs to being one instruction. Built and tested for aarch64-linux-gnu. PR target/120372 gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_rtx_costs <case CONST_INSN>): Handle if outer is COMPARE and the constant can be handled by the cmp instruction. gcc/testsuite/ChangeLog: * gcc.target/aarch64/imm_choice_comparison-2.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>