Allow range invert to fail.
Range inversion in GCC now returns a boolean to indicate success or failure, improving robustness.
The invert() function for value ranges in GCC now returns a boolean to signal whether the inversion was successful or not. This change handles cases where a range cannot be represented after inversion, preventing potential issues in subsequent optimizations and adding new test cases to verify this behavior.
In Details
The prange::invert and irange::invert functions in value-range.cc previously did not explicitly handle cases where a range inversion could not be represented (e.g., inverting a full range). This commit modifies them to return bool, allowing callers like calc_switch_ranges and snap_subranges to check for inversion success. This prevents undefined behavior and improves the robustness of range-based optimizations.
- Value Range Analysis
- A compiler optimization technique that determines the possible range of values a variable or expression can take during program execution.
- Range Inversion
- The process of calculating the range of values that satisfy a given condition, often used in optimizing conditional statements or pointer arithmetic.
- GIMPLE
- GCC's primary intermediate representation, designed for optimization passes.
- SSA
- Static Single Assignment form. An intermediate representation where every variable is assigned exactly once.