[GHC] #9451: Incorrect optimizations involving negative zero

GHC ghc-devs at haskell.org
Sun Aug 17 14:49:12 UTC 2014


#9451: Incorrect optimizations involving negative zero
-------------------------------------+-------------------------------------
       Reporter:  manzyuk            |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  Compiler           |                 Version:  7.8.3
       Keywords:                     |        Operating System:
   Architecture:  Unknown/Multiple   |  Unknown/Multiple
     Difficulty:  Unknown            |         Type of failure:  Incorrect
     Blocked By:                     |  result at runtime
Related Tickets:                     |               Test Case:
                                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 The program

 {{{#!hs
 main = print $ if negativeZero == 0.0 then 1 / negativeZero else 0.0
   where
     negativeZero = negate 0.0
 }}}

 outputs `-Infinity` when compiled with GHC 7.6.3 and `Infinity` when
 compiled with GHC 7.8.3 and the optimization level -O2.  The relevant
 pieces of Core:

 {{{
 -- GHC 7.6.3
 Main.main2 =
   case GHC.Prim.==## (GHC.Prim.negateDouble# 0.0) 0.0 of _ {
     GHC.Types.False -> Main.main3 (GHC.Types.[] @ GHC.Types.Char);
     GHC.Types.True ->
       case GHC.Prim./## 1.0 (GHC.Prim.negateDouble# 0.0)
       of wild2_aK6 { __DEFAULT ->
       GHC.Float.$w$sshowSignedFloat
         GHC.Float.$fShowDouble_$sshowFloat
         GHC.Show.shows26
         wild2_aK6
         (GHC.Types.[] @ GHC.Types.Char)
       }
   }
 }}}

 {{{
 -- GHC 7.8.3
 Main.main2 =
   case GHC.Prim.negateDouble# 0.0 of _ [Occ=Dead] {
     __DEFAULT -> Main.main3 (GHC.Types.[] @ GHC.Types.Char);
     0.0 ->
       case GHC.Prim./## 1.0 0.0 of wild2_a1NU { __DEFAULT ->
       GHC.Float.$w$sshowSignedFloat
         GHC.Float.$fShowDouble_$sshowFloat
         GHC.Show.shows27
         wild2_a1NU
         (GHC.Types.[] @ GHC.Types.Char)
       }
   }
 }}}

 I don't think this problem is operating system/architecture dependent, but
 for the sake of completeness I'm on a 32-bit Linux, and this issue was
 first discovered on 64-bit Windows running in a virtual machine.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9451>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list