Skip to content

expDouble## 0.0## doesn't get complied into 1.0##

[nix-shell:/tmp]$ cat T.hs 
{-# LANGUAGE MagicHash #-}
{-# OPTIONS_GHC -O2 -ddump-simpl -ddump-to-file #-}
module T (f) where

import GHC.Float
import GHC.Prim

f :: Double
f = D# (expDouble# 0.0## -## 1.0##)

[nix-shell:/tmp]$ ghc -fforce-recomp T.hs 
[1 of 1] Compiling T                ( T.hs, T.o )

[nix-shell:/tmp]$ cat T.dump-simpl 

==================== Tidy Core ====================
2018-12-12 02:23:40.288094743 UTC

Result size of Tidy Core
  = {terms: 20, types: 6, coercions: 0, joins: 0/0}

-- RHS size: {terms: 5, types: 0, coercions: 0, joins: 0/0}
f :: Double
[GblId,
 Str=m,
 Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
         WorkFree=False, Expandable=False, Guidance=IF_ARGS [] 15 20}]
f = GHC.Types.D# (-## (expDouble# 0.0##) 1.0##)

This was spotted in real code where we had GHC generate something like

1# ->
  jump $j9_s1IVU
    (GHC.Prim.+##
       sc3_s2pVI
       (GHC.Prim.-##
          (GHC.Prim.expDouble#
             0.0##)
          1.0##))

I would expect this (I think reasonably) to be just {{{jump $j9_s1IVU sc3_s2pVI}}}.

Maybe expDouble## <literal>## should always evaluate at compile time to not block further constant folding?

Trac metadata
Trac field Value
Version 8.6.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information