GCC Bugzilla – Bug 7003
[ppc] address of array loaded int register twice without any need
Last modified: 2005-12-07 04:13:01 UTC
File test3.c: extern const char flags [256]; unsigned char * f (unsigned char * s) { while (flags[*++s]); while (!flags[*++s]); return s; } Produced code (PowerPC): f: lis 4,flags@ha la 11,flags@l(4) .L2: lbzu 5,1(3) lbzx 4,11,5 cmpwi 0,4,0 bne+ 0,.L2 lis 6,flags@ha la 11,flags@l(6) .L5: lbzu 8,1(3) lbzx 7,11,8 cmpwi 0,7,0 beq+ 0,.L5 blr Note: address of 'flags' array loaded into register 11 twice. Why? Register 11 does not change from first load to second. Release: 3.1 20020510 (prerelease) Environment: ../gcc-3.1/configure --with-gcc-version-trigger=/home/install/gcc-3.1/gcc/version.c --host=i686-pc-linux-gnu --with-newlib --enable-target-optspace --target=ppc-eabi --prefix=/home/crossGCC/ppc-eabi --with-local-prefix=/home/crossGCC/ppc-eabi --program-prefix=ppc-eabi- --enable-languages=c,c++ -v --norecursion How-To-Repeat: ppc-eabi-gcc -S -O3 test3.c -Wall See test3.s
From: Dara Hazeghi <dhazeghi@yahoo.com> To: gcc-gnats@gcc.gnu.org Cc: Subject: Re: optimization/7003: [ppc] address of array loaded int register twice without any need Date: Wed, 14 May 2003 17:58:38 -0700 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- trail&database=gcc&pr=7003 Hello, I can confirm that gcc 3.2.3, 3.3 branch and mainline (20030508) all still exhibit this behavior. Dara
confirmed on mainline (20030523).
GCC needs two GCSE passes to get rid of this; the first pass to get rid of the high-half load, and the second for the full load. Try --param max-gcse-passes=2 . Maybe this should be default on PowerPC 32-bit?
Sounds like MIPS have some of the same issues: http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01040.html
The way to fix this do the following conversion and make sure that the address is not prograted back like it is correctly on the tree-ssa: unsigned char *f1 (unsigned char *s) { const char *flags1 = &flags[0]; while (flags1[*++s]); while (!flags1[*++s]); return s; }
Fixed in 4.2.0 by: 2005-11-24 Paolo Bonzini <bonzini@gnu.org> * gcse.c (hash_scan_set): Look through REG_EQUAL or REG_EQUIV notes also when doing PRE, rather than only for global CPROP.
Subject: Bug 7003 Author: pinskia Date: Fri Sep 28 01:02:30 2007 New Revision: 128856 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128856 Log: 2007-09-27 Andrew Pinski <andrew_pinski@playstation.sony.com> PR middle-end/7003 * gcc.target/powerpc/gcse-1.c: New test. Added: trunk/gcc/testsuite/gcc.target/powerpc/gcse-1.c Modified: trunk/gcc/testsuite/ChangeLog