This is the mail archive of the gcc-bugs@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]
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
>Closed-Date:
>Last-Modified:
>Originator:     John Reiser
>Release:        gcc version 3.1
>Organization:
>Environment:
../gcc-3.1/configure --with-gcc-version-trigger=/home/gcc-3.1/gcc/version.c --host=i686-pc-linux-gnu --norecursion
>Description:
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.
>How-To-Repeat:
$ 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
>Fix:
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.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/x-gzip; name="bug.i.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug.i.gz"

H4sICLYG6DwCA2J1Zy5pANVU246iMBi+5yn+OFlDddxAuCAbkBchxnBopQGLgeI4M+Hd9y8toOLc
7c325vvPx7Zv4MIq7U6/s5X1pugw7Xgld1xEoyCrz+dE5FBxQUfh7OFPTCdafhI0h6wWrYRz0pbH
lMs2PsAevi3A49wcPO8z7b5r9Az6BplG16Bn0DfI2BTDZVrmGfQNMo2uQc+gbxCBWX1gWQ098VbS
BriQUELSnu3VL5reVgSV9IYaAXNnRaIM047Fh+C1dsPFkYp8qeVIfNFX8otsMNe15rl1ovKjSS42
sfTA1LHtyXZDhuQkdtRMnxQqLYl3LlY2ujJeVcfBxXbILNa2GGGte9Gl3fmVsMPw7tYUDTtdJQlD
L7B6y2plInk2bVyVrTZtqxnq7Yv7DljdgB0EBGbReJ4uzRWLmi+OOMB64TGPZXPf/1o3FZdR5B0I
RBHY/rokd11P3TOwnWhvl7DdY52vqhpPQ2WHu7oug/QLyTAzsbScVjqr+nmGOFj1ruZRXigt/8tZ
/sNR/jQy+XmhOWVPL67LimCpaou6kdC1P+uKjsmjyG8BrqLpMi0YOsCIQANDpAMheC1Mdxhz3PMY
AqTie9Vd/xhuUyT4ttUuuWBVIukx/xTJmWf4xIetDiqdwlRXPXDigUsrXKqvRHPq6oYyR8keEktl
ui6SGA3CUP0KaCGU+x9ly5GqRsePglf07j8hHEJ17cC0/BhY/RwYfQvTXU0rs6rhTcl8F6Wa54ov
h+FY0x1w1B/yF0/+wbR5BgAA


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