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

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

https://gcc.gnu.org/g:d35883717679f486bb5b2b5ef546d0eda9878874

commit r17-6592-gd35883717679f486bb5b2b5ef546d0eda9878874
Author: Kyrylo Tkachov <[email protected]>
Date:   Fri Nov 20 03:04:53 2026 -0800

    aarch64: Cost MOVK as a single instruction in aarch64_rtx_costs [PR128058]

    Since 53c3316a8c7 (PR tree-optimization/108477), expand emits a PLUS
    instead of an IOR or XOR for operands with disjoint bits, so
    (x & 0xffff) | 0x12340000 becomes (plus (and x 0xffff) 0x12340000).
    The *aarch64_movk<mode> pattern matches that form, but combine rejects
    the 3 to 2 insn combination of the constant move and the PLUS when the
    immediate is neither an ADD immediate nor a 24-bit ADD pair, because
    aarch64_rtx_costs charges a separate immediate move for it.  This
    regressed gcc.target/aarch64/movk_2.c.

    Before:
            mov     w1, 305397760
            add     w0, w1, w0, uxth
            ret

    After:
            movk    w0, #0x1234, lsl 16
            ret

    Add aarch64_movk_plus_p to recognise the (plus (and R MASK) IMM) shape
    accepted by aarch64_movk_shift.  Check it at the start of the PLUS case
    of aarch64_rtx_costs, before the ADD immediate costing, and cost the
    operation as one logical instruction on R.  The check is before the
    cost_plus label because the COMPARE case jumps there with OP0 and OP1
    set to the operands of the COMPARE.

    The IOR and XOR forms need no change, because expand does not emit them
    for disjoint operands.

    Bootstrapped and tested on aarch64-linux-gnu.

    gcc/ChangeLog:

            PR target/128058
            * config/aarch64/aarch64.cc (aarch64_movk_plus_p): New function.
            (aarch64_rtx_costs): Use it to cost MOVK patterns in the PLUS case.

    gcc/testsuite/ChangeLog:

            PR target/128058
            * gcc.target/aarch64/movk_5.c: New test.

    Signed-off-by: Kyrylo Tkachov <[email protected]>

Reply via email to