tree-optimization/128943 - Avoid leaking conditional value-numbering equivalences.
Fixes PRE to avoid hoisting operations with undefined overflow, preventing incorrect signed overflow by not leaking conditional equivalences.
This commit addresses an issue in GCC’s value-numbering (VN) pass where equivalences derived from narrow operations with potential overflow were incorrectly made available globally. This could lead the Partial Redundancy Elimination (PRE) pass to hoist such operations across control flow paths where they were not valid, resulting in undefined signed overflow. The fix prevents these conditional equivalences from being recorded globally, ensuring they are only used within their valid execution contexts. This resolves PR tree-optimization/128943.
In Details
In tree-ssa-sccvn.cc, visit_nary_op previously inserted equivalences into the global nary table even if they relied on a narrow operation with undefined overflow. This made the equivalence available in blocks not dominated by the narrow operation's guard. PRE could then hoist the operation, causing undefined signed overflow. The fix restricts inserting equivalences into the nary table when they are derived from narrow operations or negated operands with undefined overflow, unless the type guarantees no overflow. This prevents incorrect hoisting and resolves PR128943.
- tree-optimization
- GCC's intermediate representation (Tree) optimization passes, which operate on a high-level representation of the code.
- value-numbering (VN)
- An optimization technique that identifies and merges equivalent expressions to avoid redundant computations.
- Partial Redundancy Elimination (PRE)
- An optimization pass that eliminates redundant computations by hoisting them to dominance points.
- undefined signed overflow
- An arithmetic operation where the result exceeds the maximum or minimum value representable by a signed integer type, leading to unpredictable behavior.
- dominance
- In control flow graphs, a block A dominates block B if every path from the entry node to B must go through A.