<div dir="ltr">Ah, yes, so just to give a concrete example in this thread, if we take the `foo` function above and say `map foo ls`, we may well get unevaluated arguments to foo.  (And this is almost precisely the same as the first example that Strict-Core paper!)<div><br></div><div>Thanks for the paper reference.  I read it and it's great -- just what I was looking for.  An approach that eliminates any jealousy of ML/Scheme compiler techniques vis a vis calling conventions ;-).  I'm also wondering if there are some incremental steps that can be taken, short of what is proposed in the paper.</div><div><ol><li>Small tweaks: The CMM code above seems to be <i>betting</i> than the thunk is unevaluated, because it does the stack check and stack write <i>before</i> the predicate test that checks if the thunk is evaluated (<span style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap;color:rgb(167,29,93)">if</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap"> (R1 & </span><span style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap;color:rgb(0,134,179)">7</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap"> != </span><span style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap;color:rgb(0,134,179)">0</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap">) </span><span style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap;color:rgb(167,29,93)">goto</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap"> c3aO; </span><span style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap;color:rgb(167,29,93)">else</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap"> </span><span style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap;color:rgb(167,29,93)">goto</span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18.2px;white-space:pre-wrap"> c3aP;</span>).  With a bang-pattern function, couldn't it make the opposite bet?  That is, branch on whether the thunk is evaluated first, and then the wasted computation is only a single correctly predicted branch (and a read of a tag that we need to read anyway). <br><br></li><li>The option of multiple entrypoints which is considered and discarded as fragile in the beginning of the paper (for direct call vs indirect / 1st order vs higher order).  That fragile option is along the lines of what I wanted to discuss on this thread.  It does seem like a tricky phase ordering concern, but how bad is it exactly?  The conflict with the a case-expr rewrite is illustrated clearly in the paper, but that just means that such optimizations must happen <i>before </i>the final choice of which function entrypoint to call, doesn't it?  I'm not 100% sure where it could go in the current compiler pipeline, but couldn't the adjustment of call target from "foo" to "foo_with_known_whnf_args" happen quite late?  </li></ol></div><div>Cheers,</div><div>  -Ryan</div><div><br></div><div>P.S. One of the students CC'd, Ryan Scott, is currently on internship at Intel labs and is working to (hopefully) liberate the Intell Haskell Research Compiler as open source.  Like the 2009 paper, it also uses a strict IR, and I think it will be interesting to see exactly how it handles the conversion from Core to its IR.  (Probably the same as Fig 10 in the paper.)</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 23, 2015 at 10:11 AM, Simon Peyton Jones <span dir="ltr"><<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">





<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">It’s absolutely the case that bang patterns etc tell the caller what to do, but the function CANNOT ASSUME that its argument is evaluated.  Reason: higher order functions.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">I think that the way to allow functions that can assume their arg is evaluated is through types: see
<a href="http://research.microsoft.com/~simonpj/papers/strict-core/tacc-hs09.pdf" target="_blank">
Type are calling conventions</a>.  But it’d be a fairly big deal to implement.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">Simon<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">                                  
<u></u><u></u></span></p>
<div style="border-style:none none none solid;border-left-color:blue;border-left-width:1.5pt;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-style:solid none none;border-top-color:rgb(225,225,225);border-top-width:1pt;padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>]
<b>On Behalf Of </b>Ryan Newton<br>
<b>Sent:</b> 23 October 2015 14:54<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>; Ömer Sinan Ağacan; Ryan Scott; Chao-Hong Chen; Johan Tibell<br>
<b>Subject:</b> Better calling conventions for strict functions (bang patterns)?<u></u><u></u></span></p>
</div>
</div><div><div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Hi all,<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
With module-level Strict and StrictData pragmas coming soon, one obvious question is what kind of the code quality GHC can achieve for strict programs.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
When it came up in discussion in our research group we realized we didn't actually know whether the bang patterns, `f !x`, on function arguments were enforced by caller or callee.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Here's a Gist that shows the compilation of a trivial function:<u></u><u></u></p>
</div>
<div>
<table border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;border-spacing:0px">
<tbody>
<tr>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border:1pt solid rgb(238,238,238);padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(121,93,163)">foo</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">::</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">Maybe</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">Int</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">-></span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">Int</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"><u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">foo !x =<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">  </span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">case</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> x
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">of</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"><u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">   </span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">Just</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> y -> y<u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
   <a href="https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fgist.github.com%2frrnewton%2f1ac722189c65f26fe9ac&data=01%7c01%7csimonpj%40064d.mgd.microsoft.com%7cb006dcdbfe834ebb6c1e08d2dbb16c03%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=qxrT8r1VSP97xQUF2qqkLlxEtSGi9VOzfmORl25W%2fWY%3d" target="_blank">https://gist.github.com/rrnewton/1ac722189c65f26fe9ac</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
If that function is compiled to *assume* its input is in WHNF, it should be just as efficient as the isomorphic MLton/OCaml code, right?  It only needs to branch on the tag, do a field dereference, and return.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
But as you can see from the STG and CMM generated, foo <i>does indeed</i> enter the thunk, adding an extra indirect jump.  Here's the body:<u></u><u></u></p>
</div>
<div>
<table border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;border-spacing:0px">
<tbody>
<tr>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border:1pt solid rgb(238,238,238);padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">      c3aY:<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">if</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> ((Sp + -</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">)
 < SpLim) </span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">goto</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> c3aZ;
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">else</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">goto</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> c3b0;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">      c3aZ:<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(150,152,150)">// nop</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"><u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          R1 = PicBaseReg + foo_closure;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">call</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> (I64[BaseReg -
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">])(R2, R1) args:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">, res:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">0</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">, upd:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">      c3b0:<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          I64[Sp -
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">] = PicBaseReg + block_c3aO_info;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          R1 = R2;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          Sp = Sp -
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">if</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> (R1 &
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">7</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> !=
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">0</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">)
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">goto</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> c3aO;
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">else</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">goto</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> c3aP;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">      c3aP:<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">call</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> (I64[R1])(R1) returns to c3aO, args:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">, res:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">, upd:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">      c3aO:<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">if</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> (R1 &
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">7</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> >=
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">2</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">)
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">goto</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> c3aW;
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">else</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(167,29,93)">goto</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> c3aX;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">      c3aW:<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          R1 = P64[R1 +
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">6</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">] & (-</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">);<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          Sp = Sp +
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">call</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> (I64[R1])(R1) args:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">, res:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">0</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">, upd:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">      c3aX:<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          R1 = PicBaseReg + lvl_r39S_closure;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          Sp = Sp +
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">;<u></u><u></u></span></p>
</td>
</tr>
<tr>
<td width="50" nowrap valign="top" style="width:37.5pt;border-style:none solid solid;border-right-color:rgb(238,238,238);border-bottom-color:rgb(238,238,238);border-left-color:rgb(238,238,238);border-right-width:1pt;border-bottom-width:1pt;border-left-width:1pt;padding:0cm 7.5pt;min-width:50px;color:rgba(0,0,0,0.298039)">
</td>
<td valign="top" style="padding:0cm 7.5pt;word-wrap:normal;overflow:visible">
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm;line-height:13.65pt">
<span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">          </span>
<span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">call</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)"> (I64[R1])(R1) args:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">, res:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">0</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">, upd:
</span><span style="font-size:9pt;font-family:Consolas;color:rgb(0,134,179)">8</span><span style="font-size:9pt;font-family:Consolas;color:rgb(51,51,51)">;<u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
The call inside c3aP is entering "x" as a thunk, which also incurs all of the stack limit check code.  I believe that IF the input could be assumed to be in WHNF, everything above the label "c3aO" could be omitted.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
So... if GHC is going to be a fabulous pure <i>and</i> imperative language, and a fabulous lazy
<i>and</i> strict compiler/runtime.. is there some work we can do here to improve this situation? Would the following make sense:<u></u><u></u></p>
</div>
<div>
<ul type="disc">
<li class="MsoNormal">
Put together a benchmark suite of all-strict programs with Strict/StrictData (compare a few benchmark's generated code to MLton, if time allows)<u></u><u></u></li><li class="MsoNormal">
Modify GHC to change calling conventions for bang patterns -- caller enforces WHNF rather than callee.  Existing strictness/demand/cardinality analysis would stay the same.<u></u><u></u></li></ul>
</div>
<div>
<p class="MsoNormal">Unless there's something I'm really missing here, the result should be that you can have a whole chain of strict function calls, each of which knows its arguments and the arguments it passes to its callees are all in WHNF, without ever
 generating thunk-entry sequences.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks for your time,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">  -Ryan<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div></div>