summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-loop-niter.c
diff options
context:
space:
mode:
authoramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>2016-07-22 13:22:03 +0000
committeramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>2016-07-22 13:22:03 +0000
commit1b793819d037eb289923368c5633536e4aa63444 (patch)
tree576e003c572da7e4109e775e6be5e94022b7de89 /gcc/tree-ssa-loop-niter.c
parent660633dba6ae7801c67efd93fe7eb5f99f924bb3 (diff)
downloadgcc-1b793819d037eb289923368c5633536e4aa63444.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@238641 138bc75d-0d04-0410-961f-82ee72b054a4
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,