public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: jreiser@BitWagon.com To: gcc-gnats@gcc.gnu.org Subject: optimization/6722: global register hoisted out of loop containing a call Date: Sun, 19 May 2002 13:46:00 -0000 [thread overview] Message-ID: <20020519203604.27750.qmail@sources.redhat.com> (raw) >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
next reply other threads:[~2002-05-19 20:46 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-05-19 13:46 jreiser [this message] 2002-06-16 17:08 rth
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20020519203604.27750.qmail@sources.redhat.com \ --to=jreiser@bitwagon.com \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).