This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc 2.95.3-test2 strange interaction between -O3 and -fPIC


I've encountered what seems to be a "bug" (or at least a fairly big
annoyance) when using -O3 together with -fPIC in gcc 2.95.3-test2
(also occurs in 2.95.2, but doesn't occur in CodeSourcery's gcc version
2.97 20010119 (experimental)).
The code emitted will run correctly, but includes extra unreachable code
(it is unconditionally branched over).  When the pattern in "case 0" is
repeated a lot (as it is in my case), a great deal of unreachable code is
generated.  This unreachable code contains a reference to a function
(doNothing) that I was hoping the optimizer would completely remove
(because of the "if (0)...",
which is currently causing me linking problems.  While I consider that
annoying, others may say "tough luck," and I'm ok with that, but the large
amount of unreachable code could be a performance concern (icache issues
and all that).   Either changing the -O3 to -O2, or removing the -fPIC from
the compile line removes the unreachable code (as does removing one or
more of the empty cases from the switch statement, or removing the loop
from findVal()!).

I'm hoping that since the behavior seems to be fixed in
2.97 20010119 (experimental) that it might be an easy patch to
2.95.3?

Here's the smallest example I could make that shows this:

% /usr/local/testgcc/bin/gcc -v -S -O3 -fPIC n3.c
Reading specs from
/usr/local/testgcc/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/specs
gcc version 2.95.3 20010112 (prerelease)

/usr/local/testgcc/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/cpp0 -lang-c -v -D__
GNUC__=2 -D__GNUC_MINOR__=95 -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -
D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__OPTI
MIZE__ -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpenti
umpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ -D__PIC__ -D__pic_
_ n3.c /tmp/ccgHK2DL.i
GNU CPP version 2.95.3 20010112 (prerelease) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include

/usr/local/testgcc/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../i686-pc-
linux-gnu/include
 /usr/local/testgcc/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:

/usr/local/testgcc/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/
g++-
End of omitted list.
 /usr/local/testgcc/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/cc1
/tmp/ccgHK2DL.i -quiet -dumpbase n3.c -O3 -version -fPIC -o n3.s
GNU C version 2.95.3 20010112 (prerelease) (i686-pc-linux-gnu) compiled by
GNU C version 2.95.3 20010112 (prerelease).

here's the file:

extern int key;

int
findVal(int val)
{
    int i;

    for (i = 0; i < 12; i++)
    {
        if ( key == val )
        return 1;
    }
    return 0;
}

void          doNothing( int x, ... );

void
doSomething( int foo )
{
    switch ( foo )
    {
     case 0 :
       if (0)
           (void) doNothing ( 0, 1, "%d accessType:\n",  findVal( 0 ) );
      break;

     case 1:
     case 2:
     case 5:
     case 10:
        break;
    }
}


--
Ken Whaley
ken@believe.com <mailto:ken@believe.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]