Bug 7003 - [ppc] address of array loaded int register twice without any need
: [ppc] address of array loaded int register twice without any need
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: rtl-optimization
: 3.1
: P3 enhancement
: 4.2.0
Assigned To: Not yet assigned to anyone
: http://gcc.gnu.org/ml/gcc-patches/200...
: missed-optimization, patch
:
:
  Show dependency treegraph
 
Reported: 2002-06-12 05:26 UTC by fshvaige
Modified: 2005-12-07 04:13 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-07 03:53:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description fshvaige 2002-06-12 05:26: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
Comment 1 Dara Hazeghi 2003-05-14 17:58:38 UTC
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
Comment 2 Andrew Pinski 2003-05-24 00:44:32 UTC
confirmed on mainline (20030523).
Comment 3 Segher Boessenkool 2003-09-29 15:52:51 UTC
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?
Comment 4 Andrew Pinski 2004-03-14 22:42:08 UTC
Sounds like MIPS have some of the same issues:
http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01040.html
Comment 5 Andrew Pinski 2004-04-08 15:44:32 UTC
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;
}
Comment 6 Andrew Pinski 2005-12-07 04:13:01 UTC
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.
Comment 7 Andrew Pinski 2007-09-28 01:03:15 UTC
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