GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
aarch64 Performance Win

MOVK instruction costing improved for aarch64.

aarch64_rtx_costs now correctly identifies and costs MOVK patterns generated from certain arithmetic operations as a single instruction.

This commit addresses a regression in the aarch64 backend where a specific pattern involving (plus (and x MASK) IMM) was not being correctly recognized as a single MOVK instruction. This was due to the cost model (aarch64_rtx_costs) charging a separate cost for an immediate move. The fix introduces aarch64_movk_plus_p to identify this pattern and cost it as a single logical instruction, resolving a test case failure and improving code generation efficiency.

In Details

The aarch64 backend's cost model in aarch64_rtx_costs has been updated to correctly handle patterns that expand into (plus (and R MASK) IMM). Previously, the PLUS case in aarch64_rtx_costs would incorrectly charge for a separate immediate move, hindering the aarch64_movk_shift pattern's ability to combine it into a single MOVK instruction. The new predicate aarch64_movk_plus_p is checked before the generic ADD immediate costing, ensuring that such combinations are recognized as a single instruction, crucial for optimizing constant initializations and manipulations.

For Context
aarch64
The 64-bit ARM architecture instruction set.
MOVK
An ARM instruction that inserts an immediate value into a specific portion (e.g., top half) of a register.
RTX
Representation of intermediate code in GCC, used after the GENERIC phase. It's a low-level, instruction-like representation.
Cost Model
A component of the compiler's optimization passes that estimates the execution cost (e.g., instruction count, latency, throughput) of different code sequences to guide optimization decisions.
Immediate
A constant value embedded directly within an instruction, as opposed to a value fetched from memory or a register.
Filed Under: aarch64optimizationcost-model