Ranger-fold: Avoid calling gimple_stmt_nonnegative_p with varying ranges.
Range folding now correctly handles varying ranges by setting the range to `[type_min, type_max]` instead of calling `gimple_stmt_nonnegative_p`.
The range folding optimization now correctly handles varying ranges by setting the range to [type_min, type_max] when the precision is different from the type’s min/max values, avoiding an infinite recursion. Previously, it would call gimple_stmt_nonnegative_p, which always returned true for unsigned types, leading to incorrect range assumptions. This fix prevents potential recursion issues and may improve code generation, particularly for Ada.
In Details
The ranger-fold subsystem performs range analysis and folding on GIMPLE IR. This commit modifies fold_using_range::fold_stmt to avoid calling gimple_stmt_nonnegative_p when dealing with varying ranges. Instead, it sets the range to [type_min, type_max] if the type's min/max differs from its precision. This change is relevant when the tree expression's nonnegative property is being determined via the ranger. The issue could lead to recursion.
For Context
Range analysis is a compiler optimization technique that tracks the possible range of values a variable can hold during program execution. Range folding uses this information to simplify expressions and perform constant propagation. GIMPLE is the simplified intermediate representation (IR) used by GCC for optimization. By improving the accuracy of range analysis, the compiler can generate more efficient code, potentially eliminating unnecessary computations and improving performance. This change targets a specific case where the range analysis was leading to incorrect assumptions, preventing further optimizations.