This addresses PR30318 that is about VRP not creating anti-ranges out of overflowing PLUS/MINUS_EXPR. Fixing this PR can possibly make removing undefined signed overflow assumptions from VRP less harmful. In order to do so this patch enhances certain parts of VRP to handle anti-ranges better and canonicalizes certain anti-ranges back to ranges. In the quest to tackle this PR I have started to re-work int_const_binop to get rid of the vrp_int_const_binop wrapper in VRP. What this patch does is expose the new proposed interface under a different name and not touch the old one (to keep patch size down). The new interface get's rid of the nearly unused "notrunc" argument (and so always force_fits_type), adds a type argument and a second output, a boolean whether the operation overflowed (regardless of definedness or undefinedness). This avoids creating a new node just to set the overflow flag and also allows tracking overflow for unsigned types just as vrp_int_const_binop tried to do. A new force_fit_type_1 was added to allow tracking of unsigned overflow here. We can implement both old interfaces, int_const_binop and force_fit_type using the new helpers, but I didn't yet change those to keep the patch small. Suggestions for a better name for int_const_binop_1 welcome ;) Note that I will split out the fold-const.c parts into a separate patch if the general idea is ok - I just included them with the VRP patch to make the intended use visible. Bootstrapped and tested on x86_64-unknown-linux-gnu. Note this patch relies on wrapping types wrapping in two's complement way. I have no idea how for example Ada types with range [1, 11] is supposed to "wrap" -- with the patch we assume that adding 5 to a range [10,10] will result in [15, 15] as it wraps according to TYPE_PRECISION, not TYPE_MIN/MAX_VALUE. So this part of the VRP patch needs to be guarded appropriately - I'm just wondering about the Ada semantics here. Comments? Thanks, Richard. 2007-01-07 Richard Guenther PR tree-optimization/30318 * tree.h (int_const_binop_1): Export. * fold-const.c (force_fit_type_1): New static function. (int_const_binop_1): New function. * tree-vrp.c (set_value_range): Canonicalize anti-ranges to ranges where possible. (extract_range_from_assert): Merge anti-ranges if possible. (vrp_int_const_binop): Remove. (extract_range_from_binary_expr): Separate MIN_EXPR and MAX_EXPR cases, merge PLUS_EXPR and MINUS_EXPR cases. Handle cases where PLUS_EXPR and MINUS_EXPR create an anti-range. Replace uses of vrp_int_const_binop by int_const_binop_1. (compare_range_with_value): Handle anti-range with no valid value. * gcc.dg/tree-ssa/vrp31.c: New testcase.