Take: ``` int f(int a, int b) { if (a != b) __builtin_unreachable(); return a/b; } ``` This only is optimized in dom. If we are going to remove dom, then it is best if the ranger optimizes it. We need a op1_op2_relation_effect for the division operators.
Need to handle % too. That is: ``` int f1(int a, int b) { if (a != b) __builtin_unreachable(); return a%b; } ``` is 0.
For a hint on this one see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126743#c1 also.
The master branch has been updated by Daniel Barboza <dbarboza@gcc.gnu.org>: https://gcc.gnu.org/g:7c25b09da5841ce372415a97c557509a8a0bb468 commit r17-3610-g7c25b09da5841ce372415a97c557509a8a0bb468 Author: Daniel Barboza <daniel.barboza@oss.qualcomm.com> Date: Mon Aug 17 11:17:39 2026 -0300 range-op.cc: add VREL_EQ relation effect for div and mod [PR126745] For res = a / b and a == b, set 'res' to one. For res = a % b and a == b, set 'res' to zero. Both are done by dom2/dom3 already. With this change we're now doing it earlier (with -O2) in evrp. Bootstrapped and regtested in x86_64. PR tree-optimization/126745 gcc/ChangeLog: * range-op.cc (operator_div::op1_op2_relation_effect): add VREL_EQ range equal one for op1/op2 and op1%op2 if op1 == op2. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr126745.c: New test.
Fixed.