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

Perform inverse converted +- lookup in Value Numbering

Fixes incorrect code generation for arithmetic operations in Value Numbering.

This commit corrects an issue in Value Numbering where an arithmetic operation was assumed to not overflow, leading to incorrect code generation for certain conversions. The fix adjusts how these operations are processed to ensure they are handled correctly, regardless of the order they appear in the intermediate representation. This change also broadens the applicability of the optimization to include sign changes and targets like ILP32.

In Details

The value numbering pass (VN) in GCC normalizes expressions. Previously, it performed a rewrite for (T)a +- X to (T)(a +- X') assuming no overflow, which was incorrect if the original program didn't execute the narrow operation. This commit reverts that rewrite and instead implements the equivalence by looking up the narrow operation a +- X' in visit_nary_op and converting its result. This ensures the equivalence is established regardless of expression order and is valid for sign changes and widening conversions where the narrow operation dominates.

For Context
Value Numbering (VN)
A compiler optimization pass that identifies and merges equivalent expressions. It assigns a unique number (value number) to each distinct expression, enabling the reuse of computed values and the elimination of redundant calculations.
Intermediate Representation (IR)
A representation of the program used internally by the compiler during various optimization and transformation stages. GCC uses several forms, including GIMPLE.
ILP32
A data model where integers and pointers are 32 bits wide. This contrasts with LP64 where pointers are 64 bits and integers can be 32 or 64 bits.
Filed Under: optimizationcompiler bug