aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-06-04 21:56:10 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2007-06-04 21:56:10 +0000
commit9a46cc164cb00570e964fe608f216e872eaa9301 (patch)
tree9e1c2c180f4cb7684e89144b82c6168c877994e5 /gcc/tree-vrp.c
parentb9d493510e957faecdf598f64b66c6fc8fa2da62 (diff)
downloadgcc-9a46cc164cb00570e964fe608f216e872eaa9301.zip
gcc-9a46cc164cb00570e964fe608f216e872eaa9301.tar.gz
gcc-9a46cc164cb00570e964fe608f216e872eaa9301.tar.bz2
tree-vrp.c (adjust_range_with_scev): When loop is not expected to overflow, reduce overflow infinity to regular infinity.
./: * tree-vrp.c (adjust_range_with_scev): When loop is not expected to overflow, reduce overflow infinity to regular infinity. (vrp_var_may_overflow): New static function. (vrp_visit_phi_node): Check vrp_var_may_overflow. testsuite/: * gcc.dg/Wstrict-overflow-18.c: New test. From-SVN: r125319
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index e0a55a8..1867377 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -2695,6 +2695,13 @@ adjust_range_with_scev (value_range_t *vr, struct loop *loop, tree stmt,
if (compare_values (min, max) == 1)
return;
}
+
+ /* According to the loop information, the variable does not
+ overflow. If we think it does, probably because of an
+ overflow due to arithmetic on a different INF value,
+ reset now. */
+ if (is_negative_overflow_infinity (min))
+ min = tmin;
}
else
{
@@ -2707,12 +2714,60 @@ adjust_range_with_scev (value_range_t *vr, struct loop *loop, tree stmt,
if (compare_values (min, max) == 1)
return;
}
+
+ if (is_positive_overflow_infinity (max))
+ max = tmax;
}
set_value_range (vr, VR_RANGE, min, max, vr->equiv);
}
}
+/* Return true if VAR may overflow at STMT. This checks any available
+ loop information to see if we can determine that VAR does not
+ overflow. */
+
+static bool
+vrp_var_may_overflow (tree var, tree stmt)
+{
+ struct loop *l;
+ tree chrec, init, step;
+
+ if (current_loops == NULL)
+ return true;
+
+ l = loop_containing_stmt (stmt);
+ if (l == NULL)
+ return true;
+
+ chrec = instantiate_parameters (l, analyze_scalar_evolution (l, var));
+ if (TREE_CODE (chrec) != POLYNOMIAL_CHREC)
+ return true;
+
+ init = initial_condition_in_loop_num (chrec, l->num);
+ step = evolution_part_in_loop_num (chrec, l->num);
+
+ if (step == NULL_TREE
+ || !is_gimple_min_invariant (step)
+ || !valid_value_p (init))
+ return true;
+
+ /* If we get here, we know something useful about VAR based on the
+ loop information. If it wraps, it may overflow. */
+
+ if (scev_probably_wraps_p (init, step, stmt, get_chrec_loop (chrec),
+ true))
+ return true;
+
+ if (dump_file && (dump_flags & TDF_DETAILS) != 0)
+ {
+ print_generic_expr (dump_file, var, 0);
+ fprintf (dump_file, ": loop information indicates does not overflow\n");
+ }
+
+ return false;
+}
+
/* Given two numeric value ranges VR0, VR1 and a comparison code COMP:
@@ -5391,7 +5446,8 @@ vrp_visit_phi_node (tree phi)
if (vrp_val_is_max (vr_result.max))
goto varying;
- if (!needs_overflow_infinity (TREE_TYPE (vr_result.min)))
+ if (!needs_overflow_infinity (TREE_TYPE (vr_result.min))
+ || !vrp_var_may_overflow (lhs, phi))
vr_result.min = TYPE_MIN_VALUE (TREE_TYPE (vr_result.min));
else if (supports_overflow_infinity (TREE_TYPE (vr_result.min)))
vr_result.min =
@@ -5409,7 +5465,8 @@ vrp_visit_phi_node (tree phi)
if (vrp_val_is_min (vr_result.min))
goto varying;
- if (!needs_overflow_infinity (TREE_TYPE (vr_result.max)))
+ if (!needs_overflow_infinity (TREE_TYPE (vr_result.max))
+ || !vrp_var_may_overflow (lhs, phi))
vr_result.max = TYPE_MAX_VALUE (TREE_TYPE (vr_result.max));
else if (supports_overflow_infinity (TREE_TYPE (vr_result.max)))
vr_result.max =