<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi All,<div><br><div class="gmail_quote"><div dir="ltr">On Sat, Sep 15, 2018 at 6:36 PM Bert Freudenberg <<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">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:</span><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">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></blockquote><div><br></div><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Huh, interesting.</div><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Eliot, if you figure this out, please let us know what it was ...</div></div></div></blockquote><div><br></div><div>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</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>"Only interested in inlining if followed by a conditional branch."</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>inlineCAB := branchDescriptor isBranchTrue or: [branchDescriptor isBranchFalse].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>"Further, only interested in inlining = and ~= if there's a SmallInteger constant involved.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span> The relational operators successfully statically predict SmallIntegers; the equality operators do not."</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>(inlineCAB and: [primDescriptor opcode = JumpZero or: [primDescriptor opcode = JumpNonZero]]) ifTrue:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">          </span>[inlineCAB := argIsIntConst or: [rcvrIsInt]].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>inlineCAB ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">             </span>[^self genSpecialSelectorSend].</div><div><br></div>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 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, 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 good student project.<br><br></div><div class="gmail_quote">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 in the terminal in Rome and was none too fresh.  ESUG was glorious though.  Thanks to all the organisers!!</div><div class="gmail_quote"><br></div><div dir="ltr" class="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></div></div>