phiopt: clear the range info of hoisted adjacent loads
Fixes incorrect range information after hoisting adjacent loads, preventing bugs in subsequent optimizations.
The hoist_adjacent_loads optimization in GCC moves loads from within a conditional block to its head. However, it previously retained the range information computed for those loads under the condition, leading to incorrect analysis for subsequent optimizations like range propagation. This change clears that stale range information, ensuring the optimizer uses accurate data and preventing potential bugs, especially when combined with future range analysis improvements.
In Details
In tree-ssa-phiopt.cc, the hoist_adjacent_loads transform moves loads from a diamond's body to its header. Crucially, it must clear the VIRTUAL_PROB_NOTE (or similar range info) associated with the loads, as their execution context changes. The previous code retained this information, which could mislead subsequent optimizations like range_from_readonly_load or cprop when those loads are not guaranteed to execute. This commit corrects hoist_adjacent_loads to nullify the range information for the hoisted loads.
- phiopt
- Phi Optimization, a pass in GCC that optimizes Phi nodes, which are used in SSA form to represent values resulting from control flow merges.
- hoist_adjacent_loads
- An optimization pass that moves adjacent loads, which have the same load cost, from under a condition to outside the condition if they are loop-invariant.
- range info
- Information about the possible values a variable or expression can take, used by compiler optimizations to prove properties or simplify code.
- SSA
- Static Single Assignment form, an intermediate representation used by GCC where each variable is assigned exactly once, simplifying many analyses and optimizations.