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

simplify-rtx: Don't merge equal operands with side effects [PR127852]

Prevents incorrect merging of volatile memory operands in GCC's simplify-rtx, fixing lost reads.

This commit corrects a bug in GCC’s simplify-rtx pass where it could incorrectly merge two identical volatile memory operands. This merging occurred in certain PLUS and MINUS coefficient folds when operands had side effects, leading to one of two sequenced volatile reads being lost. The fix ensures that such operands with side effects are not merged, preserving the integrity of volatile memory access sequences.

In Details

The simplify_binary_operation_1 function in simplify-rtx.cc was merging identical operands even when they represented volatile memory accesses. This was problematic for folds like (X + 1) * Y - Y and (X - 1) * Y + Y when Y was a volatile MEM. The commit adds a !side_effects_p guard to the operands being merged in these specific folds, aligning with the existing guards in other folds within the function and preventing the loss of sequenced volatile operations.

For Context
simplify-rtx
A GCC optimization pass that simplifies Register Transfer Language (RTL) expressions, attempting to reduce complexity and enable further optimizations.
Volatile memory access
Accesses to memory locations declared with the volatile keyword, which guarantees that each access is performed exactly as specified in the source code, preventing compiler optimizations like reordering or caching.
RTL coefficient fold
A pattern matching and simplification technique within GCC's RTL processing that recognizes and optimizes specific arithmetic expressions, such as (X + C) * Y or X * Y + C.
Side effects
Operations that modify program state outside of returning a value, such as writing to memory or I/O operations.
Filed Under: optimizationrtlvolatilebugfix