[GHC] #16036: expDouble## 0.0## doesn't get complied into 1.0##

#16036: expDouble## 0.0## doesn't get complied into 1.0## -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{ [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 {{{#!haskell 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? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16036 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16036: expDouble## 0.0## doesn't get complied into 1.0## -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj):
Maybe expDouble## <literal>## should always evaluate at compile time to not block further constant folding?
Yes that'd be easy to do via a rewrite rule. (See `prelude/PrelRules.hs`.) But whenever floating-point is in the picture I always worry about maintaining floating-point semantics. So someone fp- savvy should execute on this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16036#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16036: expDouble## 0.0## doesn't get complied into 1.0## -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Fuuzetsu): In LLVM source I see {{{ case 'e': if ((Name == "exp" && TLI->has(LibFunc_exp)) || (Name == "expf" && TLI->has(LibFunc_expf)) || (Name == "__exp_finite" && TLI->has(LibFunc_exp_finite)) || (Name == "__expf_finite" && TLI->has(LibFunc_expf_finite))) return ConstantFoldFP(exp, V, Ty); }}} So maybe it's fine? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16036#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16036: expDouble## 0.0## doesn't get complied into 1.0## -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by carter): For exp 0, on float or double, I believe the answe is always 1. Exactly. Note that this is ignoring negative zero. I believe that exp of negative infinity should always be positive zero. But I’ll need to think about it However, i believe that for any other constants the exact answer may depend on the rounding mode at the time of execution. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16036#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16036: expDouble## 0.0## doesn't get complied into 1.0## -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by carter): I’ll need to do some digging to figure out how to enable us to have a nice correct / exact rounding reference for all the standard functions -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16036#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC