This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/53265] Warn when undefined behavior implies smaller iteration count
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 13 Mar 2013 11:00:11 +0000
- Subject: [Bug tree-optimization/53265] Warn when undefined behavior implies smaller iteration count
- Auto-submitted: auto-generated
- References: <bug-53265-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53265
--- Comment #24 from Richard Biener <rguenth at gcc dot gnu.org> 2013-03-13 11:00:11 UTC ---
(In reply to comment #23)
> Created attachment 29661 [details]
> gcc48-pr53265.patch
>
> Updated patch as per IRC discussions. Still need to look at longbranch2.C and
> do_1.f90, then test it.
Looks good. Few comments:
+ number_of_latch_executions (loop);
add a comment what side-effect you are interested in.
+
+ /* If we know the exact number of iterations of this loop avoid all the
+ work below and most importantly do not break code with undefined
+ behavior by recording smaller maximum number of iterations. */
+ if (loop->nb_iterations
+ && TREE_CODE (loop->nb_iterations) == INTEGER_CST
+ && loop->any_upper_bound
+ && loop->nb_iterations_upper_bound.ucmp
+ (tree_to_double_int (loop->nb_iterations)) < 0)
+ loop->nb_iterations_upper_bound = tree_to_double_int
(loop->nb_iterations);
We don't avoid any work, so adjust the comment. I'd also simply do:
/* If we know the exact number of iterations record that as the
upper bound as well. This avoids breaking code with undefined
behavior by eventually recording a smaller maximum. */
if (loop->nb_iterations
&& TREE_CODE (loop->nb_iterations) == INTEGER_CST)
{
loop->any_upper_bound = true;
loop->nb_iterations_upper_bound = tree_to_double_int
(loop->nb_iterations);
}
that's always correct.