PR tree-optimization/126242: Check range is defined to avoid ICE.
Fixes compiler internal errors by ensuring value range information is initialized before use in optimizations.
This commit addresses compiler internal errors (ICEs) occurring when optimizing floating-point comparisons by ensuring that value range information is properly initialized before being queried. It also refines the logic for transforming floating-point comparisons to integer ones, ensuring that intermediate integer constants are exactly representable, thus preventing incorrect transformations and improving optimization robustness.
In Details
The match.pd pattern (FTYPE) N CMP CST in GCC's tree-SSA optimizer was failing to initialize value range information in certain paths, leading to ICEs when these ranges were subsequently queried. This patch ensures range information is initialized more robustly and adds checks for undefined_p before using range bounds. It also validates that casting the constant to the floating-point type preserves its value, preventing incorrect transformations when converting to integer comparisons.
- ICE
- Internal Compiler Error. A crash within the compiler itself, typically indicating a bug in the compiler's logic or an unhandled edge case.
- tree-SSA
- Static Single Assignment form. An intermediate representation within GCC that simplifies many optimizations by ensuring each variable is assigned exactly once.
- value range information
- Compiler analysis that determines the possible minimum and maximum values a variable or expression can hold at a particular point in the program.