This is the mail archive of the 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]
Other format: [Raw text]

optimization/6722: global register hoisted out of loop containing a call

>Number:         6722
>Category:       optimization
>Synopsis:       global register hoisted out of loop containing a call
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun May 19 13:46:01 PDT 2002
>Originator:     John Reiser
>Release:        gcc version 3.1
../gcc-3.1/configure --with-gcc-version-trigger=/home/gcc-3.1/gcc/version.c --host=i686-pc-linux-gnu --norecursion
gcc -O2 [version 3.1 i686-pc-linux-gnu] hoists a "common
subexpression" involving a global register out of loop which
contains a call that modifies the global register.
This gives bad code because the expression is evaluated
only once, instead of every time around the loop
as required by C semantics.
$ gcc -c -O2 bug.c
$ gdb bug.o
GNU gdb Red Hat Linux (5.1.90CVS-5)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...(no debugging symbols found)...
(gdb) x/25i inflate_dynamic  
0xa0 <inflate_dynamic>: push   %ebp
0xa1 <inflate_dynamic+1>:       mov    %esp,%ebp
0xa3 <inflate_dynamic+3>:       push   %edi
0xa4 <inflate_dynamic+4>:       xor    %edi,%edi
0xa6 <inflate_dynamic+6>:       push   %esi
0xa7 <inflate_dynamic+7>:       sub    $0x10,%esp
0xaa <inflate_dynamic+10>:      mov    0x0,%eax
0xaf <inflate_dynamic+15>:      mov    0x0,%edx
0xb5 <inflate_dynamic+21>:      mov    %eax,0xfffffff4(%ebp)
0xb8 <inflate_dynamic+24>:      lea    0x7(%ebx),%esi  # bug.c:61   (k + n)
0xbb <inflate_dynamic+27>:      nop
0xbc <inflate_dynamic+28>:      lea    0x0(%esi,1),%esi
                # top of loop [here] omits computation of (k + n)
0xc0 <inflate_dynamic+32>:      mov    %ebx,%eax
0xc2 <inflate_dynamic+34>:      sar    $0x3,%eax
0xc5 <inflate_dynamic+37>:      mov    (%eax,%edx,1),%eax
0xc8 <inflate_dynamic+40>:      mov    %ebx,%ecx
0xca <inflate_dynamic+42>:      and    $0x7,%ecx
0xcd <inflate_dynamic+45>:      shr    %cl,%eax
0xcf <inflate_dynamic+47>:      mov    0x1c,%ecx
0xd5 <inflate_dynamic+53>:      and    %ecx,%eax
0xd7 <inflate_dynamic+55>:      test   %esi,%esi  # bug.c:61   if (0>=(k + n))
0xd9 <inflate_dynamic+57>:      jle    0xe8 <inflate_dynamic+72>
0xdb <inflate_dynamic+59>:      call   0xdc <inflate_dynamic+60>
0xe0 <inflate_dynamic+64>:      mov    0x0,%edx
0xe6 <inflate_dynamic+70>:      jmp    0xc0 <inflate_dynamic+32>  # goto bad top of loop
(gdb) q
Expressions involving a global register must not be moved
across procedure calls, unless it has been proved that the
procedure does not modify the global register.
Content-Type: application/x-gzip; name="bug.i.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug.i.gz"


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