bscarlet / llvm-general

Rich LLVM bindings for Haskell (with transfer of LLVM IR to and from C++, detailed compilation pass control, etc.)
http://hackage.haskell.org/package/llvm-general
132 stars 38 forks source link

Support for fast-math flags #90

Closed tmcdonell closed 10 years ago

tmcdonell commented 10 years ago

I'd like support for adding fast math flags to floating point operations: http://llvm.org/docs/LangRef.html#fastmath

In particular, setting these flags is necessary for the auto-vectorizer to kick in and vectorize some kinds of operations, such as reductions.

At an example, here's a simple dot product file: https://gist.github.com/tmcdonell/9198757. Running through...

opt -O3 -S dotp.ll

and everything is nicely vectorized. However, if you delete the fast annotation to fmul and fadd on lines 18 and 19 respectively, then sadness ):

$ opt --version
LLVM (http://llvm.org/):
  LLVM version 3.4
  Optimized build with assertions.
  Built Feb 19 2014 (13:32:25).
  Default target: x86_64-apple-darwin13.0.0
  Host CPU: corei7
tvh commented 10 years ago

I too would like to see this. I tried to implement this, but I failed on the Template Haskell part.

This is what I had so far: eab5d4386ed319e9428497d6011afbf5e9c6eec4

bscarlet commented 10 years ago

This is now in 3.3.12.0 and 3.4.3.0.