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

Improve RTL expansion of doubleword multiplications.

Improves RTL expansion of doubleword multiplications by handling shifts greater than BITS_PER_WORD and preventing generation of unnecessary multiplications.

This commit improves RTL expansion of doubleword multiplications, specifically addressing cases where the constant being multiplied has BITS_PER_WORD or more trailing zeros. It teaches synth_mult that doubleword shifts by more than BITS_PER_WORD typically require two instructions. It also prevents RTL expansion from emitting multiply instructions by immediate constants 0, 1 or 2, speeding up compilation and reducing memory usage.

In Details

This patch modifies synth_mult in expmed.cc to handle doubleword shifts greater than BITS_PER_WORD correctly. The shift_cost tables are parameterized for shifts less than BITS_PER_WORD, so the patch teaches synth_mult that for scalar doubleword multiplications, a doubleword shift by more than BITS_PER_WORD typically requires two instructions. Also prevents RTL expansion of doubleword multiplications from initially emitting multiply instructions by immediate constants 0, 1 or 2.

For Context

When compiling code, the compiler transforms high-level code into low-level instructions that the CPU can execute. One of these steps is called RTL expansion, where operations like multiplication are translated into sequences of simpler instructions. This commit optimizes how double-word multiplications are handled during RTL expansion, particularly for large shifts and multiplications by small constants. This leads to more efficient code generation and faster compilation times.

Filed Under: RTL expansiondoubleword multiplicationoptimization