GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization

Fix miscompilations with value-numbering and multiple memory states

Corrects value-numbering to avoid miscompilations related to loads from multiple memory states.

This commit addresses miscompilations occurring in value-numbering when dealing with partial-defs and multiple memory states. It prevents the value-numbering pass from incorrectly recording a load that combines different memory states as a single store in the expression hashtable, thus avoiding the generation of wrong code. New test cases are included to cover these scenarios.

In Details

This addresses PRs tree-optimization/128637 and 128688, which affect the SCCVN (Sparse Conditional Constant Propagation Value Numbering) pass in tree-optimization. The issue arises from how loads combining multiple memory states are handled. Specifically, when a load is value-numbered and its resulting expression is inserted into the expression hashtable, it can be misinterpreted as a single store if not handled carefully. The fix involves using a dummy VR (Value Range) and skipping expression insertion for such loads, preventing incorrect code generation.

For Context
Value Numbering (VN)
A compiler optimization technique that identifies equivalent expressions or computations within the code and replaces redundant ones. It assigns a unique 'value number' to each distinct value computed.
Partial-defs
A situation where a memory location can be written to by multiple operations, but not all operations are guaranteed to be executed or reach a specific point in the code. This can complicate precise tracking of memory states.
GIMPLE
GCC's internal representation (IR) used after the front-end has parsed the source code. It's a three-address-like code that simplifies many optimization passes.
SSA
Static Single Assignment form. A program representation where every variable is assigned exactly once. This simplifies many dataflow analyses and optimizations. GIMPLE often uses SSA form.
Filed Under: gccoptimizationtree-optimizationvalue-numbering