gimple-fold: Fix undefined overflow handling in follow_outer_ssa_edges
Fixes incorrect code generation for undefined overflow cases in gimple-fold's SSA edge following logic.
This commit addresses an issue in GCC’s gimple-fold pass where the follow_outer_ssa_edges function could generate incorrect code when dealing with undefined integer overflows. The problem arose because the function would prematurely return without saving the global range of an SSA name, leading to incorrect range analysis and subsequent optimizations, as demonstrated in PR126313. The fix reorders operations to save the global range before the early return.
In Details
This commit modifies gimple-fold.cc to fix follow_outer_ssa_edges in handling SSA name ranges across conditional branches, specifically when undefined overflow is involved. Previously, the function returned early for types with undefined overflow *before* saving the current SSA name's global range, leading to incorrect range propagation when ifcombine later used the stale global range. The fix swaps the order: save global range, then return early if necessary.
- gimple-fold
- A GCC optimization pass that performs various folding operations on GIMPLE (GCC's internal representation) code to simplify expressions and improve efficiency.
- SSA (Static Single Assignment)
- An intermediate representation property where every variable is assigned exactly once. This simplifies many compiler analyses and optimizations.
- follow_outer_ssa_edges
- A function within GCC that traces the boundaries of SSA values across conditional control flow edges to determine their valid ranges.
- undefined overflow
- An arithmetic operation that results in a value outside the representable range for its data type, where the behavior is not defined by the language standard (e.g., signed integer overflow in C/C++).
- GIMPLE
- GCC's Generic Intermediate Representation. It's a three-address, statement-based representation used after initial parsing and before optimization.