public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Makoto Fujiwara <makoto@ki.nu> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: optimization/7427: gcc-3.1.1 -O2 problem for checksum calculation (powerpc) Date: Sun, 28 Jul 2002 18:16:00 -0000 [thread overview] Message-ID: <20020729011600.3209.qmail@sources.redhat.com> (raw) The following reply was made to PR optimization/7427; it has been noted by GNATS. From: Makoto Fujiwara <makoto@ki.nu> To: Andrew Pinski <pinskia@physics.uc.edu> Cc: gcc-gnats@gcc.gnu.org Subject: Re: optimization/7427: gcc-3.1.1 -O2 problem for checksum calculation (powerpc) Date: Mon, 29 Jul 2002 10:14:59 +0900 Andrew Pinski> Not a bug in gcc, but a bug in your code because of C aliasing rules. Andrew Pinski> > unsigned short *w = (void *)&tmp; Thanks Andrew, for super quick response. (1) 'gcc -Wall' gave nothing on the line 12. Is this still right ? (2) I have changed the code little bit and .. I have modified (a) and modifed (b) for further evaluation. (a) got printf in between while (b) does not. Code (a) with printf gave me the right sum even with -O2, but (b) gave the wrong sum. Is this right behavior of optimization ? (a) low = 0x181 hi = 0x8e84 sum = 0x68ac (b) sum = 0x8fb9 ------ (a) ------ #include <stdio.h> struct buf { int data; }; bug(m) struct buf *m; { int sum = 0; struct buf tmp; unsigned short *w = (void *) &tmp; unsigned short low,hi; bzero(&tmp, sizeof tmp); tmp.data = m->data; //asm volatile ("" ::: "memory"); low = w[0]; hi = w[1]; printf("low = 0x%x\n", low); printf("hi = 0x%x\n", hi); sum += w[0]; sum += w[1]; printf("sum = 0x%x\n", sum); return 0; } main() { struct buf m; m.data = 0x12345678; bug(&m); } ----- (b) ------- #include <stdio.h> struct buf { int data; }; bug(m) struct buf *m; { int sum = 0; struct buf tmp; unsigned short *w = (void *) &tmp; unsigned short low,hi; bzero(&tmp, sizeof tmp); tmp.data = m->data; //asm volatile ("" ::: "memory"); low = w[0]; hi = w[1]; // printf("low = 0x%x\n", low); // printf("hi = 0x%x\n", hi); sum += w[0]; sum += w[1]; printf("sum = 0x%x\n", sum); return 0; } main() { struct buf m; m.data = 0x12345678; bug(&m); } ------------------ --- Makoto Fujiwara, Chiba, Japan, Narita Airport and Disneyland prefecture.
next reply other threads:[~2002-07-29 1:16 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-07-28 18:16 Makoto Fujiwara [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-07-28 18:46 Andrew Pinski 2002-07-28 15:36 Andrew Pinski 2002-07-28 15:26 makoto
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=20020729011600.3209.qmail@sources.redhat.com \ --to=makoto@ki.nu \ --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).