GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
widening_mul Performance Win

Emit zero high-half partials for operands that fit in `widening_mul`.

Optimizes `widening_mul` by skipping unnecessary calculations for operands that fit within half the width.

The widening_mul optimization pass now correctly handles operands that provably fit within half the width of the multiplication. Previously, it performed unnecessary shift and multiply operations even when the high half of such operands was zero. This change reuses the recognizer’s ‘fits’ test to emit literal zeros for the high-half partial products, simplifying the generated code and improving efficiency.

In Details

The build_long_mul_partials function previously split both operands regardless of their known size. This commit modifies it to use the recognizer's fits test. If an operand fits within the lower half-width, its high-half partial products are emitted as zeros, and the subsequent carry arithmetic folds correctly. This avoids redundant shifts and multiplies for operands known to be small.

For Context
widening_mul
An optimization pass in GCC that performs multiplication of two numbers where the result may exceed the standard integer type, often by using multiple machine instructions.
high-half partials
In a wider multiplication, the results of multiplying the most significant bits of one operand with the least significant bits of the other. 'High-half' refers to the more significant portion of the result.
recognizer
A component within GCC that analyzes the intermediate representation (like RTL) to identify patterns that can be optimized or mapped to specific machine instructions.
tree-ssa
Static Single Assignment form, an intermediate representation used by GCC that simplifies many optimizations by ensuring each variable is assigned exactly once.
Filed Under: widening_muloptimizationPR127042tree-ssa