public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Edwards, Phil" <pedwards@ball.com>
To: egcs@egcs.cygnus.com, carlo@runaway.xs4all.nl
Subject: RE: Annoying warning
Date: Fri, 30 Apr 1999 23:15:00 -0000	[thread overview]
Message-ID: <B7A6155A71B6D211BB2D0008C7B250B70905CB@daytonmsg.ball.com> (raw)
Message-ID: <19990430231500.R-7PK0FojIpkNvBKRMy_y5-AnnvUWGN1C7jv9BFyJdI@z> (raw)

+ -----Original Message-----
+ From: Joe Buck [ mailto:jbuck@Synopsys.COM ]
+ Subject: Re: Annoying warning
+ 
+ > I mentioned this to the libstdc++-v3 list some time back.  
+ The solution then
+ > was to simply remove the 'inline' since (according to the 
+ list) the egcs
+ > optimizer doesn't know how to turn tail recursion into a loop. 
+ 
+ That's incorrect: gcc does know how to eliminate tail 
+ recursion and has
+ for a long time.  RMS put that one in years ago: anyone from 
+ MIT, where
+ Scheme rules, wouldn't tolerate a compiler that can't handle 
+ tail recursion.

Hey, all I know is how to misquote from the libstdc++ list archives.  I just
work here.  Do you want fries with that?  :-)

+ I just confirmed that gcc/egcs correctly transforms and inlines a
+ tail-recursive function on the Sparc.
+ 
+ Here's my testcase.
[snip]

Worked for me.  If it hasn't already been done (I don't have the libstdc++
snapshot on this machine), it seems like the recursive fn should be
rewritten as a loop, and the 'inline' keyword re-added.  EGCS groks
tail-recursion in general, but it isn't doing so in /this/ one particular
case, for whatever reason.

Nathan Meyers sent one non-recursive implementation to libstdc++; I'll quote
from his message here:

==========================================
G++ *should* be able to inline it.  It's tail-recursive,
so is easily turned into a loop.  (This is stl/bits/stl_tree.h,
function __black_count().)

If we can't get g++ to inline it as is, we should go ahead and
manually turn it into a loop ourselves.  Something like

***
  __sum += (__node->_M_color == _S_rb_tree_black) ? 1 : 0;
  return (__node == __root) ?
    __sum : __black_count(__node->_M_parent, __root, __sum);
---
  do {
    __sum += (__node->_M_color == _S_rb_tree_black) ? 1 : 0;
    if (__node == __root) break;
    __node = __node->_M_parent;
  } while (1);
  return __sum;

And, of course, put the inline back in.

In that case there's no need for the __sum argument; it could 
be a local variable instead, though that shouldn't make any 
difference if the function actually gets inlined.
==========================================


             reply	other threads:[~1999-04-30 23:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-12  8:42 Edwards, Phil [this message]
1999-04-30 23:15 ` Edwards, Phil
  -- strict thread matches above, loose matches on Subject: below --
1999-04-11 16:02 Edwards, Phil
1999-04-11 18:21 ` Joe Buck
1999-04-30 23:15   ` Joe Buck
1999-04-30 23:15 ` Edwards, Phil
1999-04-11  7:29 Carlo Wood
1999-04-11 13:10 ` Joe Buck
1999-04-12  8:28   ` Carlo Wood
1999-04-30 23:15     ` Carlo Wood
1999-04-30 23:15   ` Joe Buck
1999-04-30 23:15 ` Carlo Wood

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=B7A6155A71B6D211BB2D0008C7B250B70905CB@daytonmsg.ball.com \
    --to=pedwards@ball.com \
    --cc=carlo@runaway.xs4all.nl \
    --cc=egcs@egcs.cygnus.com \
    /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: link
Be 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).