aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2011-05-30 11:15:20 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2011-05-30 11:15:20 +0000
commitf33211587118865c4f26f3806355441c4dfdb8b8 (patch)
tree461b8951a8882fd9c13e1232291f8e317d76f105 /gcc
parentd12d8efea8fcb3122b78b3eafb7e35fe7ec2f4bd (diff)
downloadgcc-f33211587118865c4f26f3806355441c4dfdb8b8.zip
gcc-f33211587118865c4f26f3806355441c4dfdb8b8.tar.gz
gcc-f33211587118865c4f26f3806355441c4dfdb8b8.tar.bz2
re PR tree-optimization/49218 (Incorrect optimization of a 'for' loop creates an infinite loop)
2011-05-30 Richard Guenther <rguenther@suse.de> PR tree-optimization/49218 * tree-vrp.c (adjust_range_with_scev): Properly check whether overflow occured. * gcc.c-torture/execute/pr49218.c: New testcase. From-SVN: r174429
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr49218.c20
-rw-r--r--gcc/tree-vrp.c14
4 files changed, 41 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 55522d6..e1d9f65 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@
2011-05-30 Richard Guenther <rguenther@suse.de>
+ PR tree-optimization/49218
+ * tree-vrp.c (adjust_range_with_scev): Properly check whether
+ overflow occured.
+
+2011-05-30 Richard Guenther <rguenther@suse.de>
+
* tree-ssa-forwprop.c (forward_propagate_into_comparison):
New function split out from ...
(forward_propagate_into_gimple_cond): ... here. Adjust.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 60230d8..2a504c7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2011-05-30 Richard Guenther <rguenther@suse.de>
+
+ PR tree-optimization/49218
+ * gcc.c-torture/execute/pr49218.c: New testcase.
+
2011-05-30 Ira Rosen <ira.rosen@linaro.org>
PR tree-optimization/49199
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr49218.c b/gcc/testsuite/gcc.c-torture/execute/pr49218.c
new file mode 100644
index 0000000..2fb18dd
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr49218.c
@@ -0,0 +1,20 @@
+#ifdef __SIZEOF_INT128__
+typedef __int128 L;
+#else
+typedef long long L;
+#endif
+float f;
+
+int
+main ()
+{
+ L i = f;
+ if (i <= 10)
+ do
+ {
+ ++i;
+ asm ("");
+ }
+ while (i != 11);
+ return 0;
+}
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 8fcf629..f40d0d4 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -3423,11 +3423,17 @@ adjust_range_with_scev (value_range_t *vr, struct loop *loop,
loop->nb_iterations_upper_bound,
double_int_one),
unsigned_p, &overflow);
- tem = double_int_to_tree (TREE_TYPE (init), dtmp);
/* If the multiplication overflowed we can't do a meaningful
- adjustment. */
- if (!overflow && double_int_equal_p (dtmp, tree_to_double_int (tem)))
- {
+ adjustment. Likewise if the result doesn't fit in the type
+ of the induction variable. For a signed type we have to
+ check whether the result has the expected signedness which
+ is that of the step as nb_iterations_upper_bound is unsigned. */
+ if (!overflow
+ && double_int_fits_to_tree_p (TREE_TYPE (init), dtmp)
+ && (unsigned_p
+ || ((dtmp.high ^ TREE_INT_CST_HIGH (step)) >= 0)))
+ {
+ tem = double_int_to_tree (TREE_TYPE (init), dtmp);
extract_range_from_binary_expr (&maxvr, PLUS_EXPR,
TREE_TYPE (init), init, tem);
/* Likewise if the addition did. */