News for hackers. Stuff that matters.
Re:Optimising Haskell for a tight inner loop by tenslisi on Wednesday January 08, 2014 @07:09PM (#7027833)
> The moment you start trying to compete against hand written assembly, any high level lang gets a bit quirky.

Yes, which is why I wonder why GHC went with it's own code generator instead of using LLVM? It seems like a lot of the outputted assembly would be coalesced with LLVM's optimizer passes. Is there work on this problem within the Haskell world?

Re:Optimising Haskell for a tight inner loop by carterschonwald on Wednesday January 08, 2014 @07:45PM (#7027981)
GHC has an llvm backend.

If you read the blog post, you'll see Neil mentions " tried the LLVM backend, but it generated significantly worse assembly code https://github.com/ndmitchell/blogs/blob/master/inner-loop/I...

@tenslsi : theres certainly room for improving llvm, the ghc native code gen, and pretty much any compiler generally (ghc is no different). I'm actively involved in GHC dev, and i've somewhat committed to spending some volunteer time this year improving the NCG and various backend optimization tooling.

anyways, the reddit discussion of the blog post is also pretty interesting

Re:Optimising Haskell for a tight inner loop by axman6 on Thursday January 09, 2014 @01:35AM (#7029126)
> ... tried the LLVM backend, but it generated significantly worse assembly code.

It's worth noting the LLVM version Neil tried was 2.8, from Dec 2010. LLVM has come a long way since then and I'd be surprised to see if produce such horrible code. I'm hoping Neil will do an updated post using LLVM 3.4 released last week.

Re:Optimising Haskell for a tight inner loop by sanxiyn on Thursday January 09, 2014 @06:10AM (#7029814)
My understanding is that the main problem is translating from Haskell to LLVM IR is a lossy process, not the difference between LLVM 2.8 and LLVM 3.4. This blog post demonstrates one such issue:

http://blog.omega-prime.co.uk/?p=135

Quote: "In particular, LLVM conservatively assumes that GHC's stack and the heap may alias". LLVM has to assume that short of Haskell-specific analysis, so updating to LLVM 3.4 won't help with such issues.

Re:Optimising Haskell for a tight inner loop by carterschonwald on Thursday January 09, 2014 @02:33PM (#7032605)
not quite, I think the issue is that llvm doesn't understand ghc's stack, so which I guess is the same issue :)
Re:Optimising Haskell for a tight inner loop by gnuvince on Wednesday January 08, 2014 @07:25PM (#7027907)
> Yes, which is why I wonder why GHC went with it's own code generator instead of using LLVM?

LLVM didn't exist when GHC was started.

Re:Optimising Haskell for a tight inner loop by thirsteh on Wednesday January 08, 2014 @07:38PM (#7027958)
It's pretty amazing: The initial release of GHC was in 1989.
Re:Optimising Haskell for a tight inner loop by masklinn on Thursday January 09, 2014 @02:34AM (#7029286)
Neither did the NCG though, I believe. And the NCG only finally overtook the C backend late in the 6.x cycle (6.8? 6.10?)
Re:Optimising Haskell for a tight inner loop by thirsteh on Wednesday January 08, 2014 @07:16PM (#7027865)
GHC's -fllvm flag already makes it use LLVM, although the native code generator remains the default.

This backend (usually coupled with -O2) tends to slow down compile times tremendously, but can make some math-heavy programs much faster.