public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mickey.veksler at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/55217] False -Wstrict-overflow warning
Date: Fri, 03 Oct 2014 22:18:00 -0000	[thread overview]
Message-ID: <bug-55217-4-JzUwzy1U1F@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-55217-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55217

--- Comment #5 from Michael Veksler <mickey.veksler at gmail dot com> ---
Running the delta.c example with -fdump-tree-all-all-lineno produces
delta.c.125t.vrp2. 

For some reason, stop_9 (which is the first stop_.* in the file) is initialized
with   stop_9 = barD.1593 (), but it should have been initialized with 0.
=============
  # i_17 = PHI <[delta.c : 5:36] i_10(4), [delta.c : 5:14] 10(2)>
  # .MEM_18 = PHI <.MEM_8(4), .MEM_4(D)(2)>
  [delta.c : 6:13] # .MEM_8 = VDEF <.MEM_18>
  # USE = nonlocal 
  # CLB = nonlocal 
  stop_9 = barD.1593 ();  <====== Weird reorder
  [delta.c : 5:36] i_10 = i_17 + -1;
  [delta.c : 5:22] _5 = i_10 >= 0;
  [delta.c : 5:29] _6 = stop_9 == 0;
  [delta.c : 5:26] _7 = _6 & _5;
  [delta.c : 5:5] if (_7 != 0)
    goto <bb 4>;
  else
    goto <bb 5>;

==========
This seems wrong because the first time stop == 0 is checked at the source is:
    int stop= 0;
    for (int i=10 ; i>=0 && !stop; --i) {
                            ^^^^^ <=== First time stop == 0 is checked.
        stop= bar();
    }
}


=====
This seems that VRP sees the call to bar() in the wrong place.

Another issue is that VRP sees "i>=0 && !stop", which it translates to:
Visiting statement:

=========== This gives a don't know: ===========
[delta.c : 5:26] _7 = _6 & _5;

Found new range for _7: [0, +INF]
[snip]
Predicate evaluates to: DON'T KNOW

==================================================================
>From there things go downhill. Instead of knowing that _7 implies _5 (i.e.,
i>=0), it loses this information. So VRP does not understand that in the loop
i>= 0.

=== This causes the following: ====

i_17: loop information indicates does not overflow
Induction variable (int) 9 + -1 * iteration does not wrap in statement i_10 =
i_17 + -1;
 in loop 1.
Statement i_10 = i_17 + -1;
 is executed at most 2147483657 (bounded by 2147483657) + 1 times in loop 1.
Found new range for i_17: [-INF, 10]

=================================
If it know that _7 implies _5 and hence i>=0 then it could have understood that 
i_17: [0, 10].

===== This could lead to missed optimizations (in other cases), and bogus
warnings: ===
Visiting statement:
[delta.c : 5:36] i_10 = i_17 + -1;

Found new range for i_10: [-INF(OVF), 9]


  parent reply	other threads:[~2014-10-03 22:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-05 20:21 [Bug c/55217] New: " mattiase at acm dot org
2013-12-14 23:47 ` [Bug c/55217] " mickey.veksler at gmail dot com
2014-10-03 22:18 ` mickey.veksler at gmail dot com [this message]
2021-12-13  3:06 ` [Bug middle-end/55217] " pinskia at gcc dot gnu.org
2022-02-01 12:53 ` marxin 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-55217-4-JzUwzy1U1F@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).