public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sperber at deinprogramm dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/40907]  New: -O2 generates incorrect code on i386
Date: Wed, 29 Jul 2009 17:35:00 -0000	[thread overview]
Message-ID: <bug-40907-18000@http.gcc.gnu.org/bugzilla/> (raw)

When compiling Scheme 48 with -O2, an overflow check in the internal arithmetic
gets elided. This bug showed up sometime after gcc 4.0.1.  It's in 4.4.1, and
in the 4.5-20090723 snapshot.  It's been seen on 32-bit Linux and 32-bit
FreeBSD.

The code snippet in question in c/scheme48vm-32.c is this:

 L12553: {
  b_1970X = arg0K0;
  lo_a_1971X = 65535 & a_1687X;
  lo_b_1972X = 65535 & b_1970X;
  hi_a_1973X = 65535 & (((a_1687X)>>16));
  hi_b_1974X = 65535 & (((b_1970X)>>16));
  lo_c_1975X = SMALL_MULTIPLY(lo_a_1971X, lo_b_1972X);
  v_1976X = SMALL_MULTIPLY(lo_a_1971X, hi_b_1974X);
  v_1977X = SMALL_MULTIPLY(lo_b_1972X, hi_a_1973X);
  mid_c_1978X = v_1976X + v_1977X;
  c_1979X = lo_c_1975X + (((mid_c_1978X)<<16));
  if ((0 < hi_a_1973X)) {
    if ((0 < hi_b_1974X)) {
      val_1980X = integer_multiply(arg2_1113X, y_1114X);
      SvalS = val_1980X;
      Scode_pointerS = ((Scode_pointerS) + 1);
      arg3K0 = (Scode_pointerS);
      goto L32913;}
    else {
      goto L12595;}}
  else {
    goto L12595;}}
 ...
 L12595: {
  if ((536870911 < lo_c_1975X)) {
    val_2153X = integer_multiply(arg2_1113X, y_1114X);
    SvalS = val_2153X;
    Scode_pointerS = ((Scode_pointerS) + 1);
    arg3K0 = (Scode_pointerS);
    goto L32913;}
  else {
    if ((lo_c_1975X < 0)) {

That last test never gets run, and the consequent code does not get run, even
when lo_c_1975X is negative.

I've not been able to boil the code down to a smaller snippet: Smaller programs
containing this code compile OK.


-- 
           Summary: -O2 generates incorrect code on i386
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sperber at deinprogramm dot de
 GCC build triplet: i386-unknown-freebsd7.2
  GCC host triplet: i386-unknown-freebsd7.2
GCC target triplet: i386-unknown-freebsd7.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40907


             reply	other threads:[~2009-07-29 17:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-29 17:35 sperber at deinprogramm dot de [this message]
2009-07-29 17:37 ` [Bug c/40907] " sperber at deinprogramm dot de
2009-07-29 17:40 ` pinskia at gcc dot gnu dot org
2009-07-29 17:41 ` pinskia at gcc dot gnu dot org
2009-07-29 17:42 ` sperber at deinprogramm dot de
2009-07-29 18:13 ` rguenth at gcc dot gnu dot 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-40907-18000@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).