GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
xtensa Performance Win

xtensa: Improve address legitimation for wider memory accesses.

Improves code generation for Xtensa by allowing larger displacements for memory accesses wider than 1 byte.

This commit improves the Xtensa code generator by allowing it to utilize the full displacement range available for load/store instructions when accessing memory locations wider than 1 byte. Previously, the maximum displacement was limited to 255 bytes regardless of the access size. This change enables the compiler to generate more efficient code for accesses to short and int arrays, potentially reducing the number of instructions required.

In Details

The Xtensa backend's xtensa_legitimize_address function is responsible for ensuring that memory addresses are valid for load and store instructions. This patch modifies xtensa.cc to extend the upper limit of the coverable offset if the address displacement of the corresponding machine instruction is greater than 255. This allows the compiler to take advantage of the scaled displacement available for wider memory accesses. The patch includes an example and improves code generation for large positive displacements during memory accesses wider than 1-byte.

For Context

When compiling code, the compiler needs to translate memory accesses (e.g., reading a variable from memory) into machine instructions. These instructions often include a displacement, which is an offset from a base address. This commit improves the Xtensa code generation by enabling it to use a larger displacement range for memory accesses that are larger than a single byte (e.g., accessing elements of an array of short or int). By using a larger displacement, the compiler can sometimes generate more efficient code, potentially reducing the number of instructions needed to access memory.

Filed Under: xtensacode generationoptimizationaddressing