Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between GHC's -O and -O2

cabal dist discourages you from using -O2 since it produces longer compile times and the GHC manual says:

At the moment, -O2 is unlikely to produce better code than -O.

I know that I can always benchmark the library to see if -O2 gives better performance, but I was wondering if somebody could explain what -O2 does different from -O so I could get an intuition for why they consider it unlikely to produce better code.

like image 781
Gabriella Gonzalez Avatar asked Jun 19 '12 20:06

Gabriella Gonzalez


1 Answers

-O2 performs the constructor specialization. There are some other optimizations that are only enabled at -O2 as well, including -fliberate-case, -fstatic-argument-transformation,

I have a suspicion that -O2 now always produces better code, since that recommendation dates back about 10 years.

like image 84
Don Stewart Avatar answered Sep 28 '22 17:09

Don Stewart