public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/53265] Warn when undefined behavior implies smaller iteration count
Date: Wed, 13 Mar 2013 11:01:00 -0000	[thread overview]
Message-ID: <bug-53265-4-eMHvyVpz91@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <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.


  parent reply	other threads:[~2013-03-13 11:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-07 14:09 [Bug tree-optimization/53265] New: " amonakov at gcc dot gnu.org
2012-05-07 14:21 ` [Bug tree-optimization/53265] " rguenth at gcc dot gnu.org
2013-01-29 17:23 ` jakub at gcc dot gnu.org
2013-01-31 12:13 ` jakub at gcc dot gnu.org
2013-03-11 10:15 ` rguenth at gcc dot gnu.org
2013-03-11 14:14 ` rguenth at gcc dot gnu.org
2013-03-11 14:16 ` rguenth at gcc dot gnu.org
2013-03-11 14:17 ` rguenth at gcc dot gnu.org
2013-03-11 15:49 ` jakub at gcc dot gnu.org
2013-03-11 15:59 ` rguenth at gcc dot gnu.org
2013-03-11 16:16 ` amonakov at gcc dot gnu.org
2013-03-11 16:42 ` manu at gcc dot gnu.org
2013-03-11 16:50 ` manu at gcc dot gnu.org
2013-03-11 17:11 ` jakub at gcc dot gnu.org
2013-03-12 11:25 ` jakub at gcc dot gnu.org
2013-03-12 11:26 ` jakub at gcc dot gnu.org
2013-03-12 11:30 ` jakub at gcc dot gnu.org
2013-03-12 11:48 ` jakub at gcc dot gnu.org
2013-03-12 12:37 ` jakub at gcc dot gnu.org
2013-03-12 12:41 ` jakub at gcc dot gnu.org
2013-03-12 14:15 ` jakub at gcc dot gnu.org
2013-03-12 20:10 ` jakub at gcc dot gnu.org
2013-03-12 21:48 ` jakub at gcc dot gnu.org
2013-03-13 10:36 ` jakub at gcc dot gnu.org
2013-03-13 11:01 ` rguenth at gcc dot gnu.org [this message]
2013-03-14  9:14 ` jakub at gcc dot gnu.org
2013-03-14 10:55 ` jakub at gcc dot gnu.org
2013-04-29 23:18 ` ppluzhnikov at google dot com
2013-04-30  6:07 ` jakub at gcc dot gnu.org
2013-04-30  6:46 ` jakub at gcc dot gnu.org
2014-02-16 13:14 ` jackie.rosen at hushmail dot com
2023-06-09 16:52 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53265-4-eMHvyVpz91@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).