Bug 7409 - loop optimization
Summary: loop optimization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.1.1
: P3 normal
Target Milestone: ---
Assignee: Ulrich Weigand
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-25 10:36 UTC by Hartmut Penner
Modified: 2003-07-25 17:33 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hartmut Penner 2002-07-25 10:36:00 UTC
loop_optimize deletes an insn, which should not be deleted.
This leads to a abort of an application (tcl).

Scenario:

(set (reg 128) (plus (reg fp) (const_int 176)))

(set (reg 6) (reg 128))

(set (reg 2) call ()
    (expr_list (use (reg 6))))

(set (reg 96) (reg 6))

Loop optimizer thinks register 6 is in single usage, and hence delete the insn which sets register 6. This is done,
since register 6 is call-saved and a parameter.
Delete code in loop.c:876-909.

Release:
3.1.1 20020725 (prerelease)

Environment:
s390x-linux-gnu
Comment 1 bk 2002-07-26 14:11:51 UTC
From: Bernhard Kaindl <bk@suse.de>
To: <hpenner@de.ibm.com>
Cc: <gcc-gnats@gcc.gnu.org>, <mark@codesourcery.com>,
	<uweigand@de.ibm.com>, <nobody@gcc.gnu.org>, <gcc-prs@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>, Reinhard Max <max@suse.de>
Subject: Re: optimization/7409: loop optimization 
Date: Fri, 26 Jul 2002 14:11:51 +0200 (CEST)

 On 25 Jul 2002 hpenner@de.ibm.com wrote:
 > >Description:
 > loop_optimize deletes an insn, which should not be deleted.
 > This leads to a abort of an application (tcl).
 
 Yes, it leads to an abort in different 8.x tcl versions when
 running the included testsuite on s390x with gcc-3.1.1-cvs,
 but it looks like it can be worked around by changing the
 -O1 in the Makefile ot -O0 or -O2.
 
 Just to bring all the info together, I append some mails
 also describing the problem, a testcase and a proposed fix.
 
 ---------- Forwarded message ----------
 From: Hartmut Penner <HPENNER@de.ibm.com>
 To: mark@codesourcery.com, gcc-patches@gcc.gnu.org
 Cc: uweigand@de.ibm.com
 Date: Thu, 25 Jul 2002 19:53:53 +0200
 Subject: PR 7409/Loop optimization bug patch
 
 A proposed patch for problem described in PR7409 is appended here.
 The problem was, that the usage of a register as a parameter was not taken
 into acount in the function find_single_use_in_loop.
 
 Index: loop.c
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/loop.c,v
 retrieving revision 1.389.2.7
 diff -u -r1.389.2.7 loop.c
 --- loop.c      15 Jun 2002 01:12:04 -0000      1.389.2.7
 +++ loop.c      25 Jul 2002 17:41:28 -0000
 @@ -3448,6 +3448,19 @@
    const char *fmt = GET_RTX_FORMAT (code);
    int i, j;
 
 +  if (x == PATTERN (insn) && GET_CODE (insn) == CALL_INSN)
 +    {
 +      rtx link;
 +      for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
 +       {
 +         rtx op, reg;
 +
 +         if (GET_CODE (op = XEXP (link, 0)) == USE
 +             && GET_CODE (reg = XEXP (op, 0)) == REG)
 +           regs->array[REGNO (reg)].single_usage = const0_rtx;
 +       }
 +    }
 +
    if (code == REG)
      regs->array[REGNO (x)].single_usage
        = (regs->array[REGNO (x)].single_usage != 0
 
 
 
 Mit freundlichem Gruß / Best regards,
 
 Hartmut Penner
 GCC for S/390 Development
 
 ---------- Forwarded message ----------
 
 The testcase is from Tcl and is accessibel there under the name tclUtil
 which is the file where the problem appears:
 
 http://www.suse.de/~bk/gcc/testcases/
 
 cc -S -g -O1 -fPIC tclUtil.i
 
 This is the assembler code generated to call TclFindElement (only one
 place in the file):
 
         lgfr    %r4,%r8
         la      %r1,184(%r15)
         stg     %r1,160(%r15)
         la      %r1,188(%r15)
         stg     %r1,168(%r15)
         lg      %r2,200(%r15)
         lgr     %r3,%r10
         la      %r5,192(%r15)
 +       la      %r6,176(%r15)
         brasl   %r14,TclFindElement@PLT
 
 Adding the line marked with + fixes the passing of a pointer onto the
 stack and fixes this particulare case.
 
 There are other cases on tcl which -O1 also cause segementation violations,
 I hope that the other cases are also fixed with the patch above, it's likely
 that the conditions of the other uses of TclFindElement are similar.
 
 Best Regards
 Bernhard Kaindl
 
 Research & Development  SuSE Linux S/390 and zSeries
 
Comment 2 Ulrich Weigand 2002-10-15 10:04:09 UTC
Responsible-Changed-From-To: unassigned->uweigand
Responsible-Changed-Why: Fixed.
Comment 3 Ulrich Weigand 2002-10-15 10:04:09 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed in 3.2.1 and 3.3.