User account creation filtered due to spam.

Bug 8467 - Bug in sibling call optimization
Summary: Bug in sibling call optimization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-05 12:26 UTC by franz.sirl-kernel
Modified: 2003-07-25 17:33 UTC (History)
4 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 franz.sirl-kernel 2002-11-05 12:26:00 UTC
The appended testcase aborts if compiled with -O2, adding -fno-optimize-sibling-calls makes it pass.

This is a regression from gcc-2.95.4.

Release:
gcc-3.2.1pre, gcc-3.3exp

Environment:
powerpc-linux-gnu

How-To-Repeat:
extern void abort (void);
extern void exit (int);

int aim_callhandler(int sess, int conn, unsigned short family, unsigned short type)
{
  static int i = 0;

  if (!conn)
    return 0;

  if (type == 0xffff)
    {
      return 0;
    }

  if (i >= 1)
    abort ();

  i++;
  return aim_callhandler(sess, conn, family, 0xffff);
}

int main (void)
{
  aim_callhandler (0, 1, 0, 0);
  exit (0);
}
Comment 1 franz.sirl-kernel 2002-11-06 00:20:46 UTC
From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c/8467: Bug in sibling call optimization
Date: Wed, 6 Nov 2002 00:20:46 +0100

 On Tuesday 05 November 2002 21:25, Franz.Sirl-kernel@lauterbach.com wrote:
 > >Number:         8467
 > >Category:       c
 > >Synopsis:       Bug in sibling call optimization
 > >Confidential:   no
 > >Severity:       serious
 > >Priority:       medium
 > >Responsible:    unassigned
 > >State:          open
 > >Class:          sw-bug
 > >Submitter-Id:   net
 > >Arrival-Date:   Tue Nov 05 12:26:00 PST 2002
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     Franz.Sirl-kernel@lauterbach.com
 > >Release:        gcc-3.2.1pre, gcc-3.3exp
 > >Organization:
 > >Environment:
 >
 > powerpc-linux-gnu
 >
 > >Description:
 >
 > The appended testcase aborts if compiled with -O2, adding
 > -fno-optimize-sibling-calls makes it pass.
 >
 > This is a regression from gcc-2.95.4.
 >
 > >How-To-Repeat:
 >
 > extern void abort (void);
 > extern void exit (int);
 >
 > int aim_callhandler(int sess, int conn, unsigned short family, unsigned
 > short type) {
 >   static int i = 0;
 >
 >   if (!conn)
 >     return 0;
 >
 >   if (type == 0xffff)
 >     {
 >       return 0;
 >     }
 >
 >   if (i >= 1)
 >     abort ();
 >
 >   i++;
 >   return aim_callhandler(sess, conn, family, 0xffff);
 > }
 >
 > int main (void)
 > {
 >   aim_callhandler (0, 1, 0, 0);
 >   exit (0);
 > }
 
 The 4th arg is incorrectly sign-extended during tail recursion. the .rtl dump 
 with debug_call_placeholder_verbose set to 1 in the debugger:
 
 (call_insn 94 68 96 (call_placeholder 84 0 69 79 (cond [
   (const_string "normal") (sequence [
     (insn 84 0 86 (set (reg:SI 3 r3)
                 (reg/v:SI 116)) -1 (nil)
             (nil))
     (insn 86 84 88 (set (reg:SI 4 r4)
                 (reg/v:SI 117)) -1 (nil)
             (nil))
     (insn 88 86 90 (set (reg:SI 5 r5)
                 (reg/v:SI 118)) -1 (nil)
             (nil))
     (insn 90 88 91 (set (reg:SI 6 r6)
                 (const_int 65535 [0xffff])) -1 (nil)
             (nil))
     (call_insn 91 90 93 (parallel[
                     (set (reg:SI 3 r3)
                         (call (mem:SI (symbol_ref:SI ("aim_callhandler")) [0 
 S4 A8])
                             (const_int 0 [0x0])))
                     (use (const_int 0 [0x0]))
                     (clobber (scratch:SI))
                 ] ) -1 (nil)
             (nil)
             (expr_list (use (reg:SI 6 r6))
                 (expr_list (use (reg:SI 5 r5))
                     (expr_list (use (reg:SI 4 r4))
                         (expr_list (use (reg:SI 3 r3))
                             (nil))))))
     (insn 93 91 0 (set (reg:SI 137)
                 (reg:SI 3 r3)) -1 (nil)
             (nil))
     ])
   (const_string "tail_recursion") (sequence [
     (note 69 0 70 NOTE_INSN_DELETED)
     (note 70 69 72 NOTE_INSN_DELETED)
     (insn 72 70 74 (set (reg/v:SI 116)
                 (reg/v:SI 116)) -1 (nil)
             (nil))
     (insn 74 72 76 (set (reg/v:SI 117)
                 (reg/v:SI 117)) -1 (nil)
             (nil))
     (insn 76 74 78 (set (reg/v:SI 118)
                 (reg/v:SI 118)) -1 (nil)
             (nil))
     (insn 78 76 80 (set (reg/v:SI 119)
                 (const_int -1 [0xffffffffffffffff])) -1 (nil)
             (nil))
     (jump_insn 80 78 81 (set (pc)
                 (label_ref 79)) -1 (nil)
             (nil))
     (barrier 81 80 82)
     (barrier 82 81 0)
     ])
   ])) -1 (nil)
     (nil)
     (nil))
 
 Note the difference between insn 90 in the "normal" sequence and insn 78 in 
 the "tail_recursion" sequence! The 0xffff CONST_INT got signed extended, so 
 the compiler took the "short" type of the 4th arg into account, but ignored 
 the "unsigned" one.
 
 Franz.
 

Comment 2 franz.sirl-kernel 2002-11-07 22:12:01 UTC
From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
To: gcc-gnats@gcc.gnu.org
Cc: gcc-bugs@gcc.gnu.org,
 gcc-patches@gcc.gnu.org,
 Mark Mitchell <mark@codesourcery.com>
Subject: Re: c/8467: Bug in sibling call optimization
Date: Thu, 7 Nov 2002 22:12:01 +0100

 --------------Boundary-00=_1K58ZGKQV14TE1LTMPZF
 Content-Type: text/plain;
   charset="iso-8859-1"
 Content-Transfer-Encoding: 8bit
 
 Hi,
 
 it turns out this bug is easily fixed with an intermediate move insn covering 
 the case when DECL_MODE differs from the mode of the DECL_RTL.
 
 Bootstrap on powerpc-linux-gnu is currently runnning.
 
 OK to commit patch&testcase to mainline and branch after the bootstrap 
 completed successfully?
 
 Franz.
 
 
 	PR c/8467
 	* stmt.c (tail_recursion_args): Handle DECL_MODE differing from the
 	mode of DECL_RTL case.
 
 
 --------------Boundary-00=_1K58ZGKQV14TE1LTMPZF
 Content-Type: text/plain;
   charset="iso-8859-1";
   name="gcc-tailrecursion.patch"
 Content-Transfer-Encoding: 8bit
 Content-Disposition: attachment; filename="gcc-tailrecursion.patch"
 
 Index: gcc/stmt.c
 ===================================================================
 RCS file: /cvsroot/gcc/gcc/gcc/stmt.c,v
 retrieving revision 1.248.2.4
 diff -u -p -r1.248.2.4 stmt.c
 --- gcc/stmt.c	17 Apr 2002 01:43:57 -0000	1.248.2.4
 +++ gcc/stmt.c	7 Nov 2002 20:51:44 -0000
 @@ -3351,8 +3351,18 @@ tail_recursion_args (actuals, formals)
        if (GET_MODE (DECL_RTL (f)) == GET_MODE (argvec[i]))
  	emit_move_insn (DECL_RTL (f), argvec[i]);
        else
 -	convert_move (DECL_RTL (f), argvec[i],
 -		      TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
 +	{
 +	  rtx tmp = argvec[i];
 +
 +	  if (DECL_MODE (f) != GET_MODE (DECL_RTL (f)))
 +	    {
 +	      tmp = gen_reg_rtx (DECL_MODE (f));
 +	      convert_move (tmp, argvec[i],
 +			    TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
 +	    }
 +	  convert_move (DECL_RTL (f), tmp,
 +			TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
 +	}
      }
  
    free_temp_slots ();
 
 --------------Boundary-00=_1K58ZGKQV14TE1LTMPZF--
 

Comment 3 franz.sirl-kernel 2002-11-09 11:24:34 UTC
From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
To: gcc-gnats@gcc.gnu.org
Cc: gcc-bugs@gcc.gnu.org,
 gcc-patches@gcc.gnu.org,
 Mark Mitchell <mark@codesourcery.com>
Subject: Re: c/8467: Bug in sibling call optimization
Date: Sat, 9 Nov 2002 11:24:34 +0100

 On Thursday 07 November 2002 22:12, Franz Sirl wrote:
 > Hi,
 >
 > it turns out this bug is easily fixed with an intermediate move insn
 > covering the case when DECL_MODE differs from the mode of the DECL_RTL.
 >
 > Bootstrap on powerpc-linux-gnu is currently runnning.
 >
 > OK to commit patch&testcase to mainline and branch after the bootstrap
 > completed successfully?
 >
 > Franz.
 >
 >
 > 	PR c/8467
 > 	* stmt.c (tail_recursion_args): Handle DECL_MODE differing from the
 > 	mode of DECL_RTL case.
 
 Branch bootstraps on powerpc-linux-gnu and i686-linux-gnu completed without 
 regressions.
 
 Franz.
 

Comment 4 Mark Mitchell 2002-11-10 18:23:29 UTC
From: Mark Mitchell <mark@codesourcery.com>
To: Franz Sirl <Franz.Sirl-kernel@lauterbach.com>,
   "gcc-gnats@gcc.gnu.org" <gcc-gnats@gcc.gnu.org>
Cc: "gcc-bugs@gcc.gnu.org" <gcc-bugs@gcc.gnu.org>,
   "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: c/8467: Bug in sibling call optimization
Date: Sun, 10 Nov 2002 18:23:29 -0800

 > Branch bootstraps on powerpc-linux-gnu and i686-linux-gnu completed
 > without  regressions.
 
 Check this patch in, please, and let me know when it is done.
 
 Thanks!
 
 -- 
 Mark Mitchell                mark@codesourcery.com
 CodeSourcery, LLC            http://www.codesourcery.com

Comment 5 Franz Sirl 2002-11-11 13:37:32 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed.
Comment 6 Franz Sirl 2002-11-11 20:52:41 UTC
From: sirl@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/8467
Date: 11 Nov 2002 20:52:41 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	sirl@gcc.gnu.org	2002-11-11 12:52:41
 
 Modified files:
 	gcc            : stmt.c ChangeLog 
 
 Log message:
 	2002-11-11  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
 	
 	PR c/8467
 	* stmt.c (tail_recursion_args): Handle DECL_MODE differing from the
 	mode of DECL_RTL case.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.248.2.4&r2=1.248.2.4.4.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.129&r2=1.13152.2.657.2.130
 

Comment 7 Franz Sirl 2002-11-11 20:55:33 UTC
From: sirl@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/8467
Date: 11 Nov 2002 20:55:33 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	sirl@gcc.gnu.org	2002-11-11 12:55:33
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/gcc.c-torture/execute: 20021111-1.c 
 
 Log message:
 	2002-11-11  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
 	
 	PR c/8467
 	* gcc.c-torture/execute/20021111-1.c
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20021111-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.48&r2=1.1672.2.166.2.49
 

Comment 8 Franz Sirl 2002-11-11 21:25:39 UTC
From: sirl@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/8467
Date: 11 Nov 2002 21:25:39 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	sirl@gcc.gnu.org	2002-11-11 13:25:39
 
 Modified files:
 	gcc            : stmt.c ChangeLog 
 
 Log message:
 	2002-11-11  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
 	
 	PR c/8467
 	* gcc.c-torture/execute/20021111-1.c
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&r1=1.273&r2=1.274
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.15885&r2=1.15886
 

Comment 9 Franz Sirl 2002-11-11 21:29:20 UTC
From: sirl@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/8467
Date: 11 Nov 2002 21:29:20 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	sirl@gcc.gnu.org	2002-11-11 13:29:20
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/gcc.c-torture/execute: 20021111-1.c 
 
 Log message:
 	2002-11-11  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
 	
 	PR c/8467
 	* gcc.c-torture/execute/20021111-1.c
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20021111-1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2210&r2=1.2211
 

Comment 10 franz.sirl-kernel 2002-11-11 22:29:52 UTC
From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
To: Mark Mitchell <mark@codesourcery.com>,
 "gcc-gnats@gcc.gnu.org" <gcc-gnats@gcc.gnu.org>
Cc: "gcc-bugs@gcc.gnu.org" <gcc-bugs@gcc.gnu.org>,
 "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: c/8467: Bug in sibling call optimization
Date: Mon, 11 Nov 2002 22:29:52 +0100

 On Monday 11 November 2002 03:23, Mark Mitchell wrote:
 > > Branch bootstraps on powerpc-linux-gnu and i686-linux-gnu completed
 > > without  regressions.
 >
 > Check this patch in, please, and let me know when it is done.
 
 Committed.
 
 Franz.