From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30907 invoked by alias); 19 May 2002 20:46:06 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 30708 invoked by uid 71); 19 May 2002 20:46:02 -0000 Resent-Date: 19 May 2002 20:46:02 -0000 Resent-Message-ID: <20020519204602.30706.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, jreiser@BitWagon.com Received:(qmail 27751 invoked by uid 61); 19 May 2002 20:36:04 -0000 Message-Id:<20020519203604.27750.qmail@sources.redhat.com> Date: Sun, 19 May 2002 13:46:00 -0000 From: jreiser@BitWagon.com Reply-To: jreiser@BitWagon.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/6722: global register hoisted out of loop containing a call X-SW-Source: 2002-05/txt/msg00572.txt.bz2 List-Id: >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 : push %ebp 0xa1 : mov %esp,%ebp 0xa3 : push %edi 0xa4 : xor %edi,%edi 0xa6 : push %esi 0xa7 : sub $0x10,%esp 0xaa : mov 0x0,%eax 0xaf : mov 0x0,%edx 0xb5 : mov %eax,0xfffffff4(%ebp) 0xb8 : lea 0x7(%ebx),%esi # bug.c:61 (k + n) 0xbb : nop 0xbc : lea 0x0(%esi,1),%esi # top of loop [here] omits computation of (k + n) 0xc0 : mov %ebx,%eax 0xc2 : sar $0x3,%eax 0xc5 : mov (%eax,%edx,1),%eax 0xc8 : mov %ebx,%ecx 0xca : and $0x7,%ecx 0xcd : shr %cl,%eax 0xcf : mov 0x1c,%ecx 0xd5 : and %ecx,%eax 0xd7 : test %esi,%esi # bug.c:61 if (0>=(k + n)) 0xd9 : jle 0xe8 0xdb : call 0xdc 0xe0 : mov 0x0,%edx 0xe6 : jmp 0xc0 # 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