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

forwprop: Add long-multiply low-plus variant

Enhances long-multiply optimization by recognizing and folding a 'low-plus' variant involving cross-product and shifted low parts.

This commit extends the forwprop optimization pass to recognize a ‘low-plus’ variant of long multiplication. This variant involves the cross-product of high and low parts of the operands, combined with a shifted low partial product. The optimization now correctly folds this pattern, especially when it’s part of a two-carry long multiplication, deferring the fold if conditional comparisons still require intermediate values. This improves code generation for specific multiplication scenarios.

In Details

The forwprop pass now recognizes a LOW_PART variant of long multiplication where the result is formed by xl*yl + (cross_sum << N), with cross_sum = xh*yl + xl*yh. This pattern is part of a two-carry long multiply. The fold is deferred if any comparison uses (GT, LT, GE, LE) share an operand with the PLUS expression, ensuring that necessary intermediate values are not destroyed. Once the high-part fold is complete, a subsequent forwprop pass can complete the remaining fold. This addresses PR tree-optimization/107090.

For Context
forwprop
Forward propagation is an optimization pass in GCC that attempts to simplify expressions by replacing variables with their definitions as early as possible in the program flow. It's part of the SSA (Static Single Assignment) based optimization framework.
long-multiply
A multiplication operation where the result's bit-width is twice that of the operands (e.g., multiplying two 64-bit integers to produce a 128-bit result). Optimizing these operations is crucial for performance on platforms that may not have native hardware support for such wide multiplications.
LOW_PART
Refers to the lower half of a wide result produced by an operation like a long multiply. For instance, in a 128-bit result from a 64x64 multiplication, the LOW_PART would be the lower 64 bits.
cross_sum
In the context of long multiplication, the cross sum typically refers to the sum of the products of the high part of one operand and the low part of the other, and vice versa (e.g., xh*yl + xl*yh).
PLUS
Represents an addition operation within GCC's intermediate representation (GIMPLE).
Filed Under: gccoptimizationforwproplong-multiply