Here is a test program:
main = do
n <- fmap read $ getLine :: IO Int
if (999999 == n) then putStrLn "equal" else return ()
And here is the relevant bit of core when compiled with ghc --make -O2 -ddump-to-file -ddump-simpl -dsuppress-module-prefixes -dsuppress-uniques -ddump-core-stats -ddump-inlinings
:
case readEither6 @ Int (run @ Int main3 ipv1) of _ [Occ=Dead] {
[] -> case error @ Int readEither4 of wild1 { };
: x ds1 ->
case ds1 of _ [Occ=Dead] {
[] ->
case x of _ [Occ=Dead] { I# ipv2 ->
case ipv2 of _ [Occ=Dead] {
__DEFAULT -> (# ipv, () #);
999999 -> hPutStr2 stdout main2 True ipv
}
};
: ipv2 ipv3 -> case error @ Int readEither2 of wild2 { }
}
I'm wondering if the case match on the literal 999999 is really the most efficient thing here, and if not how can I encourage GHC to turn this into a call to ==#
or something?
(My actual application is more involved)
On my Ubuntu box, the relevant core code compiled to this
The first to third line are basically equivalant to the c code
Which is about as optimal as you can get.