Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,867
    • Issues 4,867
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 457
    • Merge requests 457
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9451
Closed
Open
Created Aug 17, 2014 by manzyuk@trac-manzyuk

Incorrect optimizations involving negative zero

The program

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.

Trac metadata
Trac field Value
Version 7.8.3
Type Bug
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
Assignee
Assign to
Time tracking