https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81346
--- Comment #10 from Marc Glisse <glisse at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #9) > (In reply to Marc Glisse from comment #8) > > I think always using an unsigned type for the range check would be simpler. > > If we try to check that x>=INT_MIN+2 && x<=INT_MAX-2 with -fwrapv, int is > > still not a suitable type in which to do > > x-(INT_MIN+2)<=INT_MAX-2-(INT_MIN+2), while the issue doesn't exist with an > > unsigned type. > > I'm trying to preserve what we did before, it can be tweaked incrementally > if needed. Then you may need to check for overflow in "hi = const_binop (MINUS_EXPR, etype, hi, lo);", current build_range_check has "if (value != 0 && !TREE_OVERFLOW (value))" for the result of that operation. That should matter for instance when simplifying X/INT_MAX==0.