Range-op: Teach multiplication about non-negative results.
The range analysis pass now understands that a*a is non-negative, which helps optimize RISC-V VSETVL.
The value range propagation (VRP) pass now recognizes that the square of a variable is non-negative. This helps the compiler deduce tighter bounds for expressions involving multiplication. AArch64 and RISC-V VSETVL instructions benefit from this optimization. Two new testcases, vrp-mult-nonneg-1.c and vrp-mult-nonneg-2.c, validate the fix.
In Details
GCC's value range propagation (VRP) pass deduces the possible range of values for variables and expressions, enabling further optimizations. Integer multiplication requires special handling to relate the ranges of the operands to the range of the result. This commit adds a op1_op2_relation_effect method to operator_mult in range-op-mixed.h to propagate non-negativity when one operand is equal to the other (a*a). Search terms: GCC VRP range analysis integer multiplication
For Context
Compilers use range analysis to determine the possible values of variables and expressions at different points in the program. This allows the compiler to eliminate dead code, optimize calculations, and detect potential errors like integer overflows or division by zero. Value range propagation (VRP) is a compiler pass that refines these ranges, and complex operations, like multiplication, require careful consideration to accurately propagate value ranges.