[GHC] #7866: floor (0/0) :: Int is different with -O0 and -O1

GHC ghc-devs at haskell.org
Fri Sep 20 15:03:22 CEST 2013


#7866: floor (0/0) :: Int is different with -O0 and -O1
------------------------------------------------+--------------------------
        Reporter:  alang9                       |            Owner:
            Type:  bug                          |           Status:  new
        Priority:  normal                       |        Milestone:
       Component:  Compiler                     |          Version:  7.6.2
      Resolution:                               |         Keywords:
Operating System:  Linux                        |     Architecture:  x86_64
 Type of failure:  Incorrect result at runtime  |  (amd64)
       Test Case:                               |       Difficulty:
        Blocking:                               |  Unknown
                                                |       Blocked By:
                                                |  Related Tickets:
------------------------------------------------+--------------------------
Changes (by bgamari):

 * difficulty:   => Unknown


Comment:

 This appears to be due to the (lack of) handling of NaN in
 `compiler/nativeGen/X86/CodeGen.hs:coerceFP2Int` which in the SSE case
 lowers to a plain `CVTTSD2TIQ` instruction. In the event that the source
 is NaN, this places the indeterminate integer value (which appears to be
 0x80000000) in the destination register. Oddly enough, your test produces
 instead a value of -0x8000000000000000.

 Regardless, assuming the produce is NaN handling, it's not entirely clear
 how this should be handled without performance loss. If the goal were
 perfect "correctness" (whatever this means in the fact of NaN values being
 cast to integers), we'd want to ensure we check for an indeterminate
 result and return the "appropriate" value (which judging from the -O0
 results is apparently 0). This seems like an excessive measure, however,
 punishing all users for what is likely a rare occurrence and one that
 should be handled explicitly anyways.

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



More information about the ghc-tickets mailing list