I'm currently writing a multi-module program in Haskell. I've found a strange problem where my files aren't being optimized properly, even though I'm passing in -O2
and so on. The files in question are shared 3D vector maths modules. When compiled individually to a .o, these modules are optimized correctly. When compiled as part of a larger program using --make, they are not optimized correctly. The core is quite different.
I've put in some simple stripped-down test code into a vector.hs file:
data TestVector = TestVector !Double !Double !Double !Double
addVec :: TestVector -> TestVector -> TestVector
addVec (TestVector x1 y1 z1 w1) (TestVector x2 y2 z2 w2) =
TestVector (x1 + x2) (y1 + y2) (z1 + z2) (w1 + w2)
And imported it from main...
import Vector
This code gets compiled differently as a standalone .hs file as opposed to when I build main.hs using --make
My command line is:
ghc -tmpdir tmp -hidir hi -odir obj -fext-core -fexcess-precision -funbox-strict-fields -threaded -rtsopts -fwarn-missing-signatures -Wall -O2 Main.hs -o main
Cheers
Add
{-# INLINE addVec #-}
in main module.
GHC needs indication of that possibility before doing that optimization, if the invokator/invokated are not in the same modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With