public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: c/8639: simple integer arithmetic expression broken Date: Tue, 26 Nov 2002 06:56:00 -0000 [thread overview] Message-ID: <20021119161604.5677.qmail@sources.redhat.com> (raw) The following reply was made to PR c/8639; it has been noted by GNATS. From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de> To: steveJepsen@netscape.net Cc: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: c/8639: simple integer arithmetic expression broken Date: Tue, 19 Nov 2002 17:10:33 +0100 On Tue, Nov 19, 2002 at 02:42:14PM -0000, steveJepsen@netscape.net wrote: > >Number: 8639 > >Category: c > >Synopsis: simple integer arithmetic expression broken This is: a) real b) present in 3.2, 3.2.1 and 3.3 c) present at least in C and C++ d) A regression from 2.95.2 d) arch independant (!) e) A show stopper (IMHO) Someone please mark this as confirmed, priority high. It should probably also be reclassified as middle end. > >Confidential: no > >Severity: critical > >Priority: medium > >Responsible: unassigned > >State: open > >Class: wrong-code > >Submitter-Id: net > >Arrival-Date: Tue Nov 19 06:46:02 PST 2002 > >Closed-Date: > >Last-Modified: > >Originator: Steve Jepsen > >Release: unknown-1.0 > >Organization: > >Environment: > gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7) > >Description: > the expression: > > bug_result = (80 - 4 * intvar) / 20; > > with intvar == 1 returns 4 (should return 3) I did a few experiments with expression of the form (A-B*intvar)/C with A, B and C beeing constant. In these expressions the Bug only seems to happen if C divides A and B divides C. According to the assembler output this is rewritten as A/C - intvar/(C/B) which is NOT the same. A/C - (intvar-1+C/B)/(C/B) would be the same as far as I can see. A minimal example is this: int main () { int x = 1; int res = (80 - 4*x)/20; return res; } Compiled with gcc t.c this gives: elbereth$ gcc -Wall t.c elbereth$ a.out elbereth$ echo $? 4 elbereth$ Here's the asm output on sparc which shows that the expression is rewritten as (20 - x/5). main: !#PROLOGUE# 0 save %sp, -120, %sp !#PROLOGUE# 1 mov 1, %o0 st %o0, [%fp-20] ld [%fp-20], %o0 sll %o0, 2, %o1 mov 81, %o0 sub %o0, %o1, %o0 mov 20, %o1 call .div, 0 nop st %o0, [%fp-24] ld [%fp-24], %o0 mov %o0, %i0 nop ret restore regards Christian
next reply other threads:[~2002-11-19 16:16 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-11-26 6:56 Christian Ehrhardt [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-11-25 14:56 steveJepsen
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=20021119161604.5677.qmail@sources.redhat.com \ --to=ehrhardt@mathematik.uni-ulm.de \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@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: linkBe 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).