From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32744 invoked by alias); 28 Jul 2002 22:26:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 32723 invoked by uid 71); 28 Jul 2002 22:26:01 -0000 Resent-Date: 28 Jul 2002 22:26:01 -0000 Resent-Message-ID: <20020728222601.32722.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, makoto@ki.nu Received: (qmail 32125 invoked from network); 28 Jul 2002 22:18:26 -0000 Received: from unknown (HELO quick.ki.nu) (218.44.234.232) by sources.redhat.com with SMTP; 28 Jul 2002 22:18:26 -0000 Received: (from makoto@localhost) by quick.ki.nu (8.11.6/8.11.6) id g6SMHti08540; Mon, 29 Jul 2002 07:17:55 +0900 (JST) Message-Id: <200207282217.g6SMHti08540@quick.ki.nu> Date: Sun, 28 Jul 2002 15:26:00 -0000 From: makoto@ki.nu To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: 3.113 Subject: optimization/7427: gcc-3.1.1 -O2 problem for checksum calculation (powerpc) X-SW-Source: 2002-07/txt/msg00750.txt.bz2 List-Id: >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 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: