frange: Add a comparison function for range endpoints
Introduces a precise comparison function for floating-point range endpoints, resolving signed zero issues.
This patch introduces frange_cmp(), a new comparison function for floating-point range endpoints within the frange (value-range) analysis. Previously, GCC’s value-range analysis treated -0.0 and +0.0 as equal, but frange distinguished them. This led to discrepancies and optimistic cache invalidations. The new function ensures -0.0 is strictly ordered below +0.0, resolving these issues and simplifying future developments like multi-range support.
In Details
The frange analysis, part of GCC's value range propagation, uses endpoints to define intervals. IEEE 754 floating-point semantics treat -0.0 and +0.0 as equal for many operations, but frange historically maintained a distinction. This commit replaces ad-hoc handling of signed zeros with a canonical frange_cmp function that strictly orders -0.0 < +0.0. This resolves issues where combine_zeros would incorrectly flag changes, impacting the ranger cache. It also allows for cleaner implementation of multi-ranges.
- frange
- Abbreviation for 'floating-point range', a data structure used in GCC for value range analysis of floating-point expressions.
- Value Range Analysis
- A compiler optimization technique that determines the possible range of values an expression can take during execution. This information can be used to eliminate redundant computations or to prove properties about the program.
- Signed Zero
- In floating-point arithmetic, zero can have a sign. Positive zero (+0.0) and negative zero (-0.0) behave identically in most arithmetic operations but can be distinguished in comparisons and other specific contexts.
- IEEE 754
- The standard for floating-point computation, defining formats for representing numbers and operations on them, including rules for signed zeros.
- Ranger Cache
- An internal cache within GCC's value-range analysis that stores computed range information to avoid redundant calculations.