[GHC] #8072: Optimizations change result of div for Word

#8072: Optimizations change result of div for Word -----------------------------+------------------------------------- Reporter: Khudyakov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: x86 | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | -----------------------------+------------------------------------- Here is test case {{{ import Data.Word main :: IO () main = do print $ (maxBound :: Word) `div` 101 }}} And result of execution {{{ $ ghc -fforce-recomp -O2 --make reduce.hs && ./reduce [1 of 1] Compiling Main ( reduce.hs, reduce.o ) Linking reduce ... 2891661149 @{debian:0}~/qqq/mwc $ ghc -fforce-recomp --make reduce.hs && ./reduce [1 of 1] Compiling Main ( reduce.hs, reduce.o ) Linking reduce ... 42524428 }}} Bug is only present on 32-bit systems. It goes away if rewrite rules are disable with -fno-enable-rewrite-rules or anything but maxBound is used as first argument or second argument is forced to be a funcion argument. So it could be bug in constant folding. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8072 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8072: Optimizations change result of div for Word -------------------------------------+--------------------------- Reporter: Khudyakov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86 Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+--------------------------- Comment (by Khudyakov): GHC is 7.6.3 affected but 7.4.2 and 7.2.2 are not -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8072#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8072: Optimizations change result of div for Word -------------------------------------+--------------------------- Reporter: Khudyakov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86 Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+--------------------------- Changes (by nh2): * cc: mail@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8072#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8072: Optimizations change result of div for Word -------------------------------------+--------------------------- Reporter: Khudyakov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86 Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: 3676 -------------------------------------+--------------------------- Changes (by jstolarek): * cc: jan.stolarek@… (added) * related: => 3676 Comment: #3676 reports a similar problem - optimization changing result of arithmetical operation. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8072#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8072: Optimizations change result of div for Word -------------------------------------+--------------------------- Reporter: Khudyakov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86 Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: 3676 -------------------------------------+--------------------------- Comment (by jstolarek): And I can confirm that this happens in HEAD on 32 bits, but not on 64 bits. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8072#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8072: Optimizations change result of div for Word -------------------------------------+--------------------------- Reporter: Khudyakov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86 Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: 3676 -------------------------------------+--------------------------- Comment (by Khudyakov): I don't think #3676 is related. It's because of incorrectness of realToFrac. Funky values like NaN and ±∞ are not representable as rationals so realToFrac converts Float to Double incorrectly but specialized version does it right so this difference arise. In this bug we are dealing only with integer arithmetics. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8072#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8072: Optimizations change result of div for Word -------------------------------------+--------------------------- Reporter: Khudyakov | Owner: Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86 Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: 3676 -------------------------------------+--------------------------- Changes (by igloo): * priority: normal => high * milestone: => 7.8.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8072#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8072: Optimizations change result of div for Word
-------------------------------------+---------------------------
Reporter: Khudyakov | Owner:
Type: bug | Status: closed
Priority: high | Milestone: 7.8.1
Component: Compiler | Version: 7.6.3
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture: x86
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets: 3676
-------------------------------------+---------------------------
Changes (by igloo):
* status: new => closed
* resolution: => fixed
Comment:
Thanks for the report, and to int-e for finding the problem. Fixed by:
commit af77ef45d576fddb25acf28beb434ef431f430a0
{{{
Author: Ian Lynagh
participants (1)
-
GHC