range: Add non-negative support for built-in functions
Range optimization pass gains support for non-negative properties of several floating-point built-in functions.
The GIMPLE range optimization pass now recognizes non-negative properties for a subset of floating-point built-in functions. This enhancement allows the optimizer to infer that certain function return values are always non-negative, potentially enabling further optimizations. This is the first step towards replacing the older gimple_stmt_nonnegative_p with a more integrated range analysis.
In Details
The gimple_range_op handler has been extended to recognize non-negative properties of certain built-in functions that return real types. This involves introducing new classes, cfn_fp_nonnegative and cfn_fp_nonnegative_arg0, to encapsulate the logic. The pass now handles functions where non-negativity is independent of arguments, dependent on the first argument, or dependent on the first argument's NaN-ness. This aims to consolidate range analysis and move away from the standalone gimple_stmt_nonnegative_p check, which previously involved recursive walks.
- GIMPLE
- GCC's intermediate representation (IR) used after the parsing and high-level optimization phases. It represents code in a three-address format, simplifying further analysis and transformations.
- range optimization
- A compiler optimization technique that determines the possible range of values for variables or expressions. This information can be used to eliminate redundant checks or enable other optimizations.
- built-in functions
- Functions provided by the compiler that have a specific implementation and are often optimized for performance, such as
sin,cos, orsqrt. - non-negative
- A value that is greater than or equal to zero. Recognizing this property can aid in optimizations by providing bounds for mathematical operations.
- NaN
- Not a Number. A special floating-point value used to represent undefined or unrepresentable results, such as the result of dividing zero by zero.
- jump threading
- A compiler optimization that removes redundant jumps by redirecting them to their target if the target is known to be executed unconditionally. It can simplify control flow and enable further optimizations.