On 5/30/2026 10:49 PM, Andrew Pinski wrote: > 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]> OK. Thanks for jumping on it.
jeff
