summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-loop-niter.c
diff options
context:
space:
mode:
authorBin Cheng <bin.cheng@arm.com>2016-07-22 13:22:03 +0000
committerBin Cheng <amker@gcc.gnu.org>2016-07-22 13:22:03 +0000
commitfaa1612aa309b073803613c82712bc940393ad74 (patch)
tree576e003c572da7e4109e775e6be5e94022b7de89 /gcc/tree-ssa-loop-niter.c
parent01a0d7f57b8a0e87cde0aac7e0693bcaa5745898 (diff)
tree-ssa-loop-niter.h (number_of_iterations_exit_assumptions): New Parameter.
* tree-ssa-loop-niter.h (number_of_iterations_exit_assumptions): New Parameter. * tree-ssa-loop-niter.c (number_of_iterations_exit_assumptions): New Parameter. (number_of_iterations_exit): Warn missed loop optimization for possible infinite loops. gcc/testsuite * gcc.dg/tree-ssa/pr19210-1.c: Refine test strings. * gcc.dg/tree-ssa/pr19210-2.c: Delete. From-SVN: r238641
Diffstat (limited to 'gcc/tree-ssa-loop-niter.c')
-rw-r--r--gcc/tree-ssa-loop-niter.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 3b4d4f31502..ee6d5cfe0fd 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2132,12 +2132,13 @@ loop_only_exit_p (const struct loop *loop, const_edge exit)
in comments at struct tree_niter_desc declaration), false otherwise.
When EVERY_ITERATION is true, only tests that are known to be executed
every iteration are considered (i.e. only test that alone bounds the loop).
- */
+ If AT_STMT is not NULL, this function stores LOOP's condition statement in
+ it when returning true. */
bool
number_of_iterations_exit_assumptions (struct loop *loop, edge exit,
struct tree_niter_desc *niter,
- bool every_iteration)
+ gcond **at_stmt, bool every_iteration)
{
gimple *last;
gcond *stmt;
@@ -2254,6 +2255,9 @@ number_of_iterations_exit_assumptions (struct loop *loop, edge exit,
if (TREE_CODE (niter->niter) == INTEGER_CST)
niter->max = wi::to_widest (niter->niter);
+ if (at_stmt)
+ *at_stmt = stmt;
+
return (!integer_zerop (niter->assumptions));
}
@@ -2263,13 +2267,26 @@ number_of_iterations_exit_assumptions (struct loop *loop, edge exit,
bool
number_of_iterations_exit (struct loop *loop, edge exit,
struct tree_niter_desc *niter,
- bool, bool every_iteration)
+ bool warn, bool every_iteration)
{
+ gcond *stmt;
if (!number_of_iterations_exit_assumptions (loop, exit, niter,
- every_iteration))
+ &stmt, every_iteration))
return false;
- return (integer_nonzerop (niter->assumptions));
+ if (integer_nonzerop (niter->assumptions))
+ return true;
+
+ if (warn)
+ {
+ const char *wording;
+
+ wording = N_("missed loop optimization, the loop counter may overflow");
+ warning_at (gimple_location_safe (stmt),
+ OPT_Wunsafe_loop_optimizations, "%s", gettext (wording));
+ }
+
+ return false;
}
/* Try to determine the number of iterations of LOOP. If we succeed,