From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 587 invoked by alias); 8 Oct 2010 17:17:37 -0000 Received: (qmail 564 invoked by uid 22791); 8 Oct 2010 17:17:35 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,MISSING_MID,TW_BJ,TW_CX,TW_DC,TW_GX,TW_JL,TW_PW X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Oct 2010 17:17:30 +0000 From: "paul at pwsan dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/40893] ARM and PPC truncate intermediate operations unnecessarily X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: paul at pwsan dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Fri, 08 Oct 2010 17:17:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-10/txt/msg00752.txt.bz2 Message-ID: <20101008171700.t9xEt_0m5sa3x1MPisgnIo-74xEFDpdbFd0JGNk-y3Q@z> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40893 --- Comment #4 from paul walmsley 2010-10-08 17:17:24 UTC --- The bug also appears without volatile: ---- /* generates an unnecessary uxth */ void foo(unsigned short a, unsigned short b, unsigned short c, unsigned short *e, unsigned short *f) { *e = (a + b) + c; *f = (a + b) - c; } /* works as expected */ void bar(unsigned short a, unsigned short b, unsigned short c, unsigned short *e) { *e = (a + b) + c; } /* works as expected */ void baz(unsigned short a, unsigned short b, unsigned short c, unsigned short *e) { *e = (a + b) - c; } ----- compiled and dumped with: arm-linux-gnueabi-gcc -O2 -c test.c ; objdump -DS test.o produces: ----- Disassembly of section .text: 00000000 : 0: e0811000 add r1, r1, r0 4: e1a01801 lsl r1, r1, #16 8: e1a01821 lsr r1, r1, #16 c: e0620001 rsb r0, r2, r1 10: e0821001 add r1, r2, r1 14: e1c310b0 strh r1, [r3] 18: e59d3000 ldr r3, [sp] 1c: e1c300b0 strh r0, [r3] 20: e12fff1e bx lr 00000024 : 24: e0811000 add r1, r1, r0 28: e0822001 add r2, r2, r1 2c: e1c320b0 strh r2, [r3] 30: e12fff1e bx lr 00000034 : 34: e0811000 add r1, r1, r0 38: e0622001 rsb r2, r2, r1 3c: e1c320b0 strh r2, [r3] 40: e12fff1e bx lr ----- gcc -v: Using built-in specs. Target: arm-linux-gnueabi Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-2' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.4.5 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-sjlj-exceptions --enable-checking=release --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabi --with-headers=/usr/arm-linux-gnueabi/include --with-libs=/usr/arm-linux-gnueabi/lib Thread model: posix gcc version 4.4.5 (Debian 4.4.5-2)