Unexpected lack of optimisation in -O0

Neil Mitchell ndmitchell at gmail.com
Thu Apr 10 10:21:38 EDT 2008


Hi,

I just tried compiling the following program:

foo = (1 :: Int) == (2 :: Int)

with ghc --ddump-simpl, and no optimisation flags, in GHC 6.6.1

The resultant code is:

Test.foo =
  case GHC.Base.$f2 of tpl_X8 { GHC.Base.:DEq tpl1_B2 tpl2_B3 ->
  tpl1_B2 (GHC.Base.I# 1) (GHC.Base.I# 2)
  }

GHC has introduced dictionaries in this example. In comparison, Yhc
and nhc wouldn't introduce dictionaries here, as the type class
desugaring knows the type of the item is fixed, and makes a direct
call to the appropriate function.

If the desugaring was changed, it would make programs in GHCi run
faster, would reduce the size of programs, and would speed up the
optimiser, as it would have less to do. I am not sure how much
additional work this would require in the simplifier, but if it was
minimal, the gains would probably be worth it.

I was just reading the Monad.Reader, where a Yhc based Haskell
Interpreter states that comparisons against GHCi are "unfair", because
Yhc gains too  much benefit from this desguaring.

Thanks

Neil


More information about the Glasgow-haskell-users mailing list