[Sbcl-devel] Problem inlining nested calls to same function

11 views
Skip to first unread message

Nikodemus Siivola

unread,
May 4, 2008, 7:12:59 PM5/4/08
to sbcl-devel
(declaim (inline foo))
(defun foo (x y)
(cons x y))

(defun bar (x)
(foo (foo x x) (foo x x)))

(disassemble 'bar)

Disassembly shows a full call to FOO. I'm not yet sure why one call
doesn't get converted properly, so if someone has insights to offer,
they are very welcome. This doesn't seem to be a new bug, but
something coming all the way from CMUCL heritage.

Cheers,

-- Nikodemus

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Sbcl-devel mailing list
Sbcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-devel

Marco Antoniotti

unread,
May 6, 2008, 9:45:30 AM5/6/08
to sbcl-devel
... told you!

--
Marco Antoniotti

Raymond Toy (RT/EUS)

unread,
May 6, 2008, 3:33:03 PM5/6/08
to Nikodemus Siivola, sbcl-devel
Nikodemus Siivola wrote:
> (declaim (inline foo))
> (defun foo (x y)
> (cons x y))
>
> (defun bar (x)
> (foo (foo x x) (foo x x)))
>
> (disassemble 'bar)
>
> Disassembly shows a full call to FOO. I'm not yet sure why one call
> doesn't get converted properly, so if someone has insights to offer,
> they are very welcome. This doesn't seem to be a new bug, but
> something coming all the way from CMUCL heritage.

Wild guess: The compiler thinks a tail-call to foo is better than
inlining foo.

Ray

Nikodemus Siivola

unread,
Nov 3, 2008, 1:41:59 PM11/3/08
to Raymond Toy (RT/EUS), sbcl-devel
On Tue, May 6, 2008 at 9:33 PM, Raymond Toy (RT/EUS)
<raymo...@ericsson.com> wrote:
> Nikodemus Siivola wrote:
>>
>> (declaim (inline foo))
>> (defun foo (x y)
>> (cons x y))
>>
>> (defun bar (x)
>> (foo (foo x x) (foo x x)))
>>
>> (disassemble 'bar)
>>
>> Disassembly shows a full call to FOO. I'm not yet sure why one call
>> doesn't get converted properly, so if someone has insights to offer,
>> they are very welcome. This doesn't seem to be a new bug, but
>> something coming all the way from CMUCL heritage.
>
> Wild guess: The compiler thinks a tail-call to foo is better than inlining
> foo.

Fixed in 1.0.22.13. I didn't check, but I suspect the same fix may be
applicable to CMUCL as well.

Cheers,

-- Nikodemus

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

Raymond Toy

unread,
Nov 4, 2008, 9:21:02 AM11/4/08
to Nikodemus Siivola, sbcl-devel
Nikodemus Siivola wrote:
> On Tue, May 6, 2008 at 9:33 PM, Raymond Toy (RT/EUS)
> <raymo...@ericsson.com> wrote:
>> Nikodemus Siivola wrote:
>>> (declaim (inline foo))
>>> (defun foo (x y)
>>> (cons x y))
>>>
>>> (defun bar (x)
>>> (foo (foo x x) (foo x x)))
>>>
>>> (disassemble 'bar)
>>>
>>> Disassembly shows a full call to FOO. I'm not yet sure why one call
>>> doesn't get converted properly, so if someone has insights to offer,
>>> they are very welcome. This doesn't seem to be a new bug, but
>>> something coming all the way from CMUCL heritage.
>> Wild guess: The compiler thinks a tail-call to foo is better than inlining
>> foo.
>
> Fixed in 1.0.22.13. I didn't check, but I suspect the same fix may be
> applicable to CMUCL as well.

Interesting. The current version of cmucl actually inlines foo. I was
kind of expecting it not to inline it, just like sbcl.

But I'm keeping this message in case I do find an inline issue.

Thank for the info!

Ray

Nikodemus Siivola

unread,
Nov 4, 2008, 9:35:19 AM11/4/08
to Raymond Toy, sbcl-devel
On Tue, Nov 4, 2008 at 4:21 PM, Raymond Toy <raymo...@ericsson.com> wrote:

> Interesting. The current version of cmucl actually inlines foo. I was
> kind of expecting it not to inline it, just like sbcl.

That is interesting! Looking at the CMUCL source, CMUCL does exactly
what SBCL used to do in RECOGNIZE-KNOWN-CALL. I'm not 100% sure, but I
think CMUCL doesn't run into the same problem here thanks to it's use
of IR1-CONVERT-LAMBDA-FOR-DEFUN.

Cheers,

-- Nikodemus

Reply all
Reply to author
Forward
0 new messages