https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79119
--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> --- With POINTER_DIFF_EXPR, things may be easier. One of the things I suggested when introducing it was that VRP could always use a range of [ -PTRDIFF_MAX, PTRDIFF_MAX ] for them. If you had written __PTRDIFF_TYPE__ d = q - p; __SIZE_TYPE__ n = (d < 0) ? -d : d; that would suffice to simplify f. (With the code above, g is already optimized) We could improve phiopt abs_replacement so it understands versions with MINUS_EXPR (that's necessary for other PRs anyway), and versions with pointers. Teaching VRP that p<q implies q-p>0 looks like more work...