<div dir="ltr">Austin also raises an important point: <div><br><div>Its high time we explore changes to the ABI/per architecture calling convention and how they might impact performance.</div><div><br></div><div> I think this is something worth exploring after the 7.8 release </div>

<div>(but not in the next month of prerelease engineering, though I need to suss out some of that a bit more with the parties who care)</div><div><br></div><div>I had started working on a backwards compatible ABI change for llvm a few months back that I could easily get LLVM folks to merge in, but I&#39;d rather only give the LLVM folks 1 set of ABI change patches within a 6month period, where we&#39;ve had the time to experiment with breaking changes as an option too, rather than given them a partial patch now, and then a breaking changes calling convention patch a few months from now.</div>

<div><br></div><div>(because if we don&#39;t bundle LLVM with GHC, we need to actually tie ABI versions to LLVM major version releases, which isn&#39;t a problem, but just requires thoughtful cooperation and such)</div><div>

<br></div><div>cheers<br><div style>-Carter</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 27, 2013 at 12:51 PM, Austin Seipp <span dir="ltr">&lt;<a href="mailto:aseipp@pobox.com" target="_blank">aseipp@pobox.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To do this, IMO we&#39;d also really have to start shipping our own copy<br>
of LLVM. The current situation (use what we have configured or in<br>
$PATH) won&#39;t really become feasible later on.<br>
<br>
On platforms like ARM where there is no NCG, the mismatches can become<br>
super painful, and it makes depending on certain features of the IR or<br>
compiler toolchain (like an advanced, ISA-aware vectorizer in LLVM<br>
3.3+) way more difficult, aside from being a management nightmare.<br>
<br>
Fixing it does require taking a hit on things like build times,<br>
though. Or we could use binary releases, but we occasionally may want<br>
to tweak and/or fix things. If we ship our own LLVM for example, it&#39;s<br>
reasonable to assume sometime in the future we&#39;ll want to change the<br>
ABI during a release.<br>
<br>
This does bring other benefits. Max Bolingbroke had an old alias<br>
analysis plugin for LLVM that made a noticeable improvement on certain<br>
kinds of programs, but shipping it against an arbitrary LLVM is<br>
infeasible. Stuff like this could now be possible too.<br>
<br>
In a way, I think there&#39;s some merit to having a simple, integrated<br>
code generator that does the correct thing, with a high performance<br>
option as we have now. LLVM is a huge project, and there&#39;s definitely<br>
some part of me that thinks this may not lower our complexity budget<br>
as much as we think, only shift parts of it around (&#39;second rate&#39;<br>
platforms like PPC/ARM expose way more bugs in my experience, and<br>
tracking them across such a massive surface area can be quite<br>
difficult.) It&#39;s very stable and well tested, but an unequivocal<br>
dependency on hundreds of thousands of lines of deeply complex code is<br>
a big question no matter what.<br>
<br>
But, the current NCG isn&#39;t that &#39;simple correct thing&#39; either, though.<br>
I think it&#39;s easily one of the least understood parts of the compiler<br>
with a long history, it&#39;s rarely refactored or modified (very unlike<br>
other parts,) and it&#39;s maintained only as necessary. Which doesn&#39;t<br>
bode well for its future in any case.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Mon, Aug 26, 2013 at 3:19 PM, Simon Marlow &lt;<a href="mailto:marlowsd@gmail.com">marlowsd@gmail.com</a>&gt; wrote:<br>
&gt; On 26/08/13 08:17, Ben Lippmeier wrote:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;&gt;     &gt; Well, what&#39;s the long term plan?  Is the LLVM backend going to<br>
&gt;&gt;&gt;     become the only backend at some point?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     I wouldn&#39;t argue against ditching the NCG entirely. It&#39;s hard to<br>
&gt;&gt;&gt;     justify fixing NCG performance problems when fixing them won&#39;t<br>
&gt;&gt;&gt;     make the NCG faster than LLVM, and everyone uses LLVM anyway.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     We&#39;re going to need more and more SIMD support when processors<br>
&gt;&gt;&gt;     supporting the Larrabee New Instructions (LRBni) appear on<br>
&gt;&gt;&gt;     people&#39;s desks. At that time there still won&#39;t be a good enough<br>
&gt;&gt;&gt;     reason to implement those instructions in the NCG.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I hope to implement SIMD support for the native code gen soon. It&#39;s<br>
&gt;&gt;&gt; not a huge task and having feature parity between LLVM and NCG would<br>
&gt;&gt;&gt; be good.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;  Will you also update the SIMD support, register allocators, and calling<br>
&gt;&gt; conventions in 2015 when AVX-512 lands on the desktop? On all supported<br>
&gt;&gt; platforms? What about support for the x86 vcompress and vexpand<br>
&gt;&gt; instructions with mask registers? What about when someone finally asks<br>
&gt;&gt; for packed conversions between 16xWord8s and 16xFloat32s where you need<br>
&gt;&gt; to split the result into four separate registers? LLVM does that<br>
&gt;&gt; automatically.<br>
&gt;&gt;<br>
&gt;&gt; I&#39;ve been down this path before. In 2007 I implemented a separate graph<br>
&gt;&gt; colouring register allocator in the NCG to supposably improve GHC&#39;s<br>
&gt;&gt; numeric performance, but the LLVM backend subsumed that work and now<br>
&gt;&gt; having two separate register allocators is more of a maintenance burden<br>
&gt;&gt; than a help to anyone. At the time, LLVM was just becoming well known,<br>
&gt;&gt; so it wasn&#39;t obvious that implementing a new register allocator was a<br>
&gt;&gt; largely a redundant piece of work -- but I think it&#39;s clear now. I was<br>
&gt;&gt; happy to work on the project at the time, and I learned a lot from it,<br>
&gt;&gt; but when starting new projects now I also try to imagine the system that<br>
&gt;&gt; will replace the one I&#39;m dreaming of.<br>
&gt;&gt;<br>
&gt;&gt; Of course, you should do what interests you -- I&#39;m just pointing out a<br>
&gt;&gt; strategic consideration.<br>
&gt;<br>
&gt;<br>
&gt; The existence of LLVM is definitely an argument not to put any more effort<br>
&gt; into backend optimisation in GHC, at least for those optimisations that LLVM<br>
&gt; can already do.<br>
&gt;<br>
&gt; But as for whether the NCG is needed at all - there are a few ways that the<br>
&gt; LLVM backend needs to be improved before it can be considered to be a<br>
&gt; complete replacement for the NCG:<br>
&gt;<br>
&gt; 1. Compilation speed.  LLVM approximately doubles compilation time. Avoiding<br>
&gt; going via the textual intermediate syntax would probably help here.<br>
&gt;<br>
&gt; 2. Shared library support (#4210, #5786).  It works (or worked?) on a couple<br>
&gt; of platforms.  But even on those platforms it generated worse code than the<br>
&gt; NCG due to using dynamic references for *all* symbols, whereas the NCG knows<br>
&gt; which symbols live in a separate package and need to use dynamic references.<br>
&gt;<br>
&gt; 3. Some low-level optimisation problems (#4308, #5567).  The LLVM backend<br>
&gt; generates bad code for certain critical bits of the runtime, perhaps due to<br>
&gt; lack of good aliasing information.  This hasn&#39;t been revisited in the light<br>
&gt; of the new codegen, so perhaps it&#39;s better now.<br>
&gt;<br>
&gt; Someone should benchmark the LLVM backend against the NCG with new codegen<br>
&gt; in GHC 7.8.  It&#39;s possible that the new codegen is getting a slight boost<br>
&gt; because it doesn&#39;t have to split up proc points, so it can do better code<br>
&gt; generation for let-no-escapes. (It&#39;s also possible that LLVM is being<br>
&gt; penalised a bit for the same reason - I spent more time peering at<br>
&gt; NCG-generated code than LLVM-generated code).<br>
&gt;<br>
&gt; These are some good places to start if you want to see GHC drop the NCG.<br>
&gt;<br>
&gt; Cheers,<br>
&gt;         Simon<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; ghc-devs mailing list<br>
&gt; <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Regards,<br>
Austin - PGP: 4096R/0x91384671<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
</div></div></blockquote></div><br></div></div></div>