Skip to content

GHC can't constant fold even basic power (^) applications for Int (and others?)

[nix-shell:/tmp]$ ghc -O2 -fforce-recomp -ddump-simpl S.hs 2>&1 | tail
[GblId,
 Unf=Unf{Src=<vanilla>, TopLvl=True, Value=False, ConLike=False,
         WorkFree=False, Expandable=False, Guidance=IF_ARGS [] 50 20}]
foo
  = case GHC.Real.$wf1 2# 1# of ww2_a2zt { __DEFAULT ->
    GHC.Types.I# ww2_a2zt
    }

[nix-shell:/tmp]$ cat S.hs
module S (foo) where
foo :: Int
foo = (2 :: Int) ^ (1 :: Int)

This seems like a fairly strange thing to not optimise when constants are known on both sides. I'm complaining about Int for this particular ticket.

Edited by Mateusz Kowalczyk
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information