public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: makoto@ki.nu To: gcc-gnats@gcc.gnu.org Subject: optimization/7427: gcc-3.1.1 -O2 problem for checksum calculation (powerpc) Date: Sun, 28 Jul 2002 15:26:00 -0000 [thread overview] Message-ID: <200207282217.g6SMHti08540@quick.ki.nu> (raw) >Number: 7427 >Category: optimization >Synopsis: (powerpc) -O2 problem for checksum calc. >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Sun Jul 28 15:26:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Makoto Fujiwara >Release: 3.1.1 >Organization: office.ki.nu >Environment: System: NetBSD quick 1.5ZC NetBSD 1.5ZC (GENERIC) #0: Fri Mar 29 19:38:39 JST 2002 tsubai@mahoro:/a/0328/src/sys/arch/macppc/compile/GENERIC macppc host: powerpc--netbsd build: powerpc--netbsd target: powerpc--netbsd configured with:../configure --with-gcc-version-trigger=/export/local-src/gcc-3.1.1/gcc/version.c --host=powerpc-unknown-netbsd1.5ZC --norecursion >Description: With code attached, say, sum.c, the output with -O2 shows different value with -O or -O1. -O sum = 0x68ac -O1 sum = 0x68ac -O2 sum = 0x8fb9 >How-To-Repeat: Compile following file on macppc machine with -O1 and -O2 and execute them respectively. ------------------------------- #include <stdio.h> struct buf { int data; }; bug(m) struct buf *m; { int sum = 0; struct buf tmp; unsigned short *w = (void *)&tmp; bzero(&tmp, sizeof tmp); tmp.data = m->data; //asm volatile ("" ::: "memory"); sum += w[0]; sum += w[1]; printf("sum = 0x%x\n", sum); return 0; } main() { struct buf m; m.data = 0x12345678; bug(&m); } ------------------------------- I will attach the .s code for the reference: (1) with -O1 ......................................................................... .file "sum.c" .section .rodata .align 2 .LC0: .string "sum = 0x%x\n" .section ".text" .align 2 .globl bug .type bug,@function bug: stwu 1,-16(1) mflr 0 stw 0,20(1) lwz 0,0(3) stw 0,8(1) lhz 4,8(1) lhz 0,10(1) add 4,4,0 lis 3,.LC0@ha la 3,.LC0@l(3) crxor 6,6,6 bl printf li 3,0 lwz 0,20(1) mtlr 0 addi 1,1,16 blr .Lfe1: .size bug,.Lfe1-bug .align 2 .globl main .type main,@function main: stwu 1,-16(1) mflr 0 stw 0,20(1) lis 0,0x1234 ori 0,0,22136 stw 0,8(1) addi 3,1,8 crxor 6,6,6 bl bug lwz 0,20(1) mtlr 0 addi 1,1,16 blr .Lfe2: .size main,.Lfe2-main .ident "GCC: (GNU) 3.1.1" ......................................................................... (2) with -O2 ......................................................................... .file "sum.c" .section .rodata .align 2 .LC0: .string "sum = 0x%x\n" .section ".text" .align 2 .globl bug .type bug,@function bug: stwu 1,-16(1) mflr 0 stw 0,20(1) lhz 4,8(1) lhz 0,10(1) lwz 9,0(3) lis 3,.LC0@ha add 4,4,0 la 3,.LC0@l(3) stw 9,8(1) crxor 6,6,6 bl printf lwz 0,20(1) li 3,0 addi 1,1,16 mtlr 0 blr .Lfe1: .size bug,.Lfe1-bug .align 2 .globl main .type main,@function main: stwu 1,-16(1) mflr 0 stw 0,20(1) addi 3,1,8 lis 0,0x1234 ori 0,0,22136 stw 0,8(1) crxor 6,6,6 bl bug lwz 0,20(1) addi 1,1,16 mtlr 0 blr .Lfe2: .size main,.Lfe2-main .ident "GCC: (GNU) 3.1.1" ......................................................................... >Fix: Not known at the moment. >Release-Note: >Audit-Trail: >Unformatted:
next reply other threads:[~2002-07-28 22:26 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-07-28 15:26 makoto [this message] 2002-07-28 15:36 Andrew Pinski 2002-07-28 18:16 Makoto Fujiwara 2002-07-28 18:46 Andrew Pinski
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=200207282217.g6SMHti08540@quick.ki.nu \ --to=makoto@ki.nu \ --cc=gcc-gnats@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).