https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125513
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:61e2300bc9364a9060aca12ba189d5bbca950aff commit r17-1061-g61e2300bc9364a9060aca12ba189d5bbca950aff Author: Andrew Pinski <[email protected]> Date: Sat May 30 15:54:59 2026 -0700 range-op: Add relation effect for integer mult [PR23471] tree_expr_nonnegative_p has code to say `a*a` is nonnegative (for signed integers). But when I removed the call to gimple_stmt_nonnegative_p, ranger could not figure out that that `a*a` is nonnegative. This shows up as a regression on riscv with `gcc.target/riscv/rvv/vsetvl/avl_single-65.c`. But you can also reproduce the same issue if we disable forwprop and look at the result of EVRP and look at the exported range for that statement. The fix is to teach the range multiply operator that when dealing with `a*a`, the lhs will be non-negative. That is add a op1_op2_relation_effect method to operator_mult that handles the case where the relationship is equal. vrp-mult-nonneg-1.c is now a testcase which GCC can optimize which was not handled before. vrp-mult-nonneg-2.c is the reduced testcase for PR125513 and the regression. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/23471 PR tree-optimization/125513 gcc/ChangeLog: * range-op-mixed.h (operator_mult): Add op1_op2_relation_effect for 2xirange. * range-op.cc (operator_mult::op1_op2_relation_effect): New function. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/vrp-mult-nonneg-1.c: New test. * gcc.dg/tree-ssa/vrp-mult-nonneg-2.c: New test. Signed-off-by: Andrew Pinski <[email protected]>
