<div dir="ltr">Hi Levente,<div><br><div class="gmail_quote"><div dir="ltr">On Tue, Sep 18, 2018 at 8:21 AM Levente Uzonyi <<a href="mailto:leves@caesar.elte.hu">leves@caesar.elte.hu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Eliot,<br>
<br>
On Mon, 17 Sep 2018, Eliot Miranda wrote:<br>
<br>
> Hi All,<br>
> On Sat, Sep 15, 2018 at 6:36 PM Bert Freudenberg <<a href="mailto:bert@freudenbergs.de" target="_blank">bert@freudenbergs.de</a>> wrote:<br>
>       On Sat, Sep 15, 2018 at 4:58 PM Levente Uzonyi <<a href="mailto:leves@caesar.elte.hu" target="_blank">leves@caesar.elte.hu</a>> wrote:<br>
>       Hi Eliot,<br>
><br>
>       Here is a very simple test case:<br>
><br>
>       {<br>
>               [ 1 to: 500000000 do: [ :i | i = 1 ifTrue: [ true ] ifFalse: [ false ] ] ] timeToRun.<br>
>               [ 1 to: 500000000 do: [ :i | i = 1 ] ] timeToRun.<br>
>       }<br>
><br>
>       On my machine it gives #(992 1436).<br>
> <br>
> <br>
> Huh, interesting.<br>
> <br>
> Eliot, if you figure this out, please let us know what it was ...<br>
> <br>
> <br>
> hmmm.  It's my fault.  It is to do with the criteria the StackToRegisterMappingCogit uses to decide whether to inline comparison operations.  The code I wrote in genSpecialSelectorComparison says<br>
> <br>
> "Only interested in inlining if followed by a conditional branch."<br>
> inlineCAB := branchDescriptor isBranchTrue or: [branchDescriptor isBranchFalse].<br>
> "Further, only interested in inlining = and ~= if there's a SmallInteger constant involved.<br>
> The relational operators successfully statically predict SmallIntegers; the equality operators do not."<br>
> (inlineCAB and: [primDescriptor opcode = JumpZero or: [primDescriptor opcode = JumpNonZero]]) ifTrue:<br>
> [inlineCAB := argIsIntConst or: [rcvrIsInt]].<br>
> inlineCAB ifFalse:<br>
> [^self genSpecialSelectorSend].<br>
> <br>
> So the Cogit inlines the = 1 in the first case because it is followed by the branch for the ifTrue: [true] ifFalse: [false], but does not inline = 1 in the second case.  So the second case is a true<br>
> send, and the true send code (load a register with i, another with 1, another with the SmallInteger tag, call the checked entry point of SmallInteger>>#=, tag test the receiver, tag test the argument,<br>
> compare, reify as true or false, return) is more costly, essentially because it has a call/return.  I'll discuss with Clément and Sophie we'll think about measuring this tradeoff.  This is perhaps a<br>
> good student project.<br>
> <br>
> If anyone has good arguments why the heuristics above are bogus or good measurements please post.  In the mean time sorry for the late reply; I was airborne on the way back from Cagliari, or sleeping<br>
<br>
I see no reason to limit inlining when the result is used. When it's not <br>
used, then the program is probably incorrect.<br>
But if you want specific situations when such expressions should be <br>
jitted, then here's a quick list:<br>
<br>
- when the resulting boolean is returned. E.g.:<br>
<br>
isEmpty<br>
<br>
        ^tally = 0<br>
<br>
- when the resulting boolean is the value returned by a block:<br>
<br>
        array select: [ :each | each > 0 ]<br>
<br>
- when the resulting boolean is part of a larger boolean expression <br>
(don't know how this can be detected):<br>
<br>
        (x = 1 or: [ y = 2 ]) ifTrue: [ ... ]<br>
<br>
All in all, I think it's easier to always inline it than not. And I can't <br>
really find a reason not to inline it.<br></blockquote><div><br></div><div>Cool.  Always great to have an excuse for more JIT hacking :-)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Levente<br>
<br>
> in the terminal in Rome and was none too fresh.  ESUG was glorious though.  Thanks to all the organisers!!<br>
> <br>
> _,,,^..^,,,_<br>
> best, Eliot<br></blockquote></div><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div></div>