This fixes PR59245 by more carefully dropping TREE_OVERFLOW inside VRP (where formerly we only dropped TREE_OVERFLOW from infinities). It also adds checking ...
Bootstrapped on x86_64-unknown-linux-gnu, 2nd version in testing (if that doesn't succeed I'm going to remove the new checking again). Richard. 2013-11-26 Richard Biener <rguent...@suse.de> PR tree-optimization/59245 * tree-vrp.c (set_value_range): Assert that we don't have overflowed constants (but our infinities). (set_value_range_to_value): Drop all overflow flags. (vrp_visit_phi_node): Likewise. (vrp_visit_assignment_or_call): Use set_value_range_to_value to set a constant range. * gcc.dg/torture/pr59245.c: New testcase. Index: gcc/tree-vrp.c =================================================================== *** gcc/tree-vrp.c (revision 205380) --- gcc/tree-vrp.c (working copy) *************** set_value_range (value_range_t *vr, enum *** 441,446 **** --- 441,449 ---- gcc_assert (min && max); + gcc_assert ((!TREE_OVERFLOW_P (min) || is_overflow_infinity (min)) + && (!TREE_OVERFLOW_P (max) || is_overflow_infinity (max))); + if (INTEGRAL_TYPE_P (TREE_TYPE (min)) && t == VR_ANTI_RANGE) gcc_assert (!vrp_val_is_min (min) || !vrp_val_is_max (max)); *************** static inline void *** 616,622 **** set_value_range_to_value (value_range_t *vr, tree val, bitmap equiv) { gcc_assert (is_gimple_min_invariant (val)); ! val = avoid_overflow_infinity (val); set_value_range (vr, VR_RANGE, val, val, equiv); } --- 619,626 ---- set_value_range_to_value (value_range_t *vr, tree val, bitmap equiv) { gcc_assert (is_gimple_min_invariant (val)); ! if (TREE_OVERFLOW_P (val)) ! val = drop_tree_overflow (val); set_value_range (vr, VR_RANGE, val, val, equiv); } *************** vrp_visit_assignment_or_call (gimple stm *** 6738,6745 **** /* Try folding the statement to a constant first. */ tree tem = gimple_fold_stmt_to_constant (stmt, vrp_valueize); ! if (tem && !is_overflow_infinity (tem)) ! set_value_range (&new_vr, VR_RANGE, tem, tem, NULL); /* Then dispatch to value-range extracting functions. */ else if (code == GIMPLE_CALL) extract_range_basic (&new_vr, stmt); --- 6742,6749 ---- /* Try folding the statement to a constant first. */ tree tem = gimple_fold_stmt_to_constant (stmt, vrp_valueize); ! if (tem) ! set_value_range_to_value (&new_vr, tem, NULL); /* Then dispatch to value-range extracting functions. */ else if (code == GIMPLE_CALL) extract_range_basic (&new_vr, stmt); *************** vrp_visit_phi_node (gimple phi) *** 8336,8342 **** } else { ! if (is_overflow_infinity (arg)) arg = drop_tree_overflow (arg); vr_arg.type = VR_RANGE; --- 8340,8346 ---- } else { ! if (TREE_OVERFLOW_P (arg)) arg = drop_tree_overflow (arg); vr_arg.type = VR_RANGE; Index: gcc/testsuite/gcc.dg/torture/pr59245.c =================================================================== *** gcc/testsuite/gcc.dg/torture/pr59245.c (revision 0) --- gcc/testsuite/gcc.dg/torture/pr59245.c (working copy) *************** *** 0 **** --- 1,28 ---- + /* { dg-do compile } */ + + int a, b, c, e, g; + char d[5], f; + + int + fn1 () + { + if (b) + { + g = 0; + return 0; + } + for (f = 0; f != 1; f--) + ; + return 0; + } + + void + fn2 () + { + d[4] = -1; + for (a = 4; a; a--) + { + fn1 (); + e = c < -2147483647 - 1 - d[a] ? c : 0; + } + }