Is there a way to disable the constant folding optimization in GHC?

571 views Asked by At

I need to compiler some Haskell source code with GHC -O1 optimization but with the constant folding optimization disabled. I could not find an optimization flag for toggling constant folding in GHC manual however. Is this possible to turn off it meanwhile keep other optimizations?

1

There are 1 answers

0
ondra On

If you compile with -fno-enable-rewrite-rules, it disables constant folding. Also, IMO if you pass the constants to a NOINLINE function and use them inside the function, you stand a good chance that it doesn't get folded.