[GHC] #13425: Semantically-equivalent expressions evaluating at different values with -O1

#13425: Semantically-equivalent expressions evaluating at different values with -O1 -------------------------------------+------------------------------------- Reporter: rbasso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The following code shows inconsistent results when compiled with -O1: {{{#!hs import Data.Bits ((.&.)) flags :: Int -> [Int] flags x = filter (\y -> x .&. y > 0) [1, 128, 129, 255] main :: IO () main = do putStrLn $ show $ flags $ 255 -- These lines should display putStrLn (show (flags 255)) -- the same value, right? -- It appears that this is related to something that started -- with GHC 7.10, but was also changed in GHC 8.0, as we can -- see from the following tests: -- -- Stack snapshot lts-0.7 (GHC 7.8.3), with -O2 -- [1,128,129,255] -- [1,128,129,255] -- -- Stack snapshot lts-2.22 (GHC 7.8.4) with -O2 -- [1,128,129,255] -- [1,128,129,255] -- -- Stack snapshot lts-3.22 (GHC 7.10.2) with -O2 -- [1] -- [1] -- -- Stack snapshot lts-6.30 (GHC 7.10.3) with -O2 -- [1] -- [1] -- -- Stack snapshot lts-7.20 (GHC 8.0.1) with -O2 -- [1] -- [1,128,129,255] -- -- Stack snapshot lts-8.5 (GHC 8.0.2) with -O2 -- [1] -- [1,128,129,255] -- -- In GHC 8.0.2, compiling with any of the following... -- -O0 -- -O2 -fno-cmm-sink -- -O2 -fno-enable-rewrite-rules -- -- ...we get the expected results: -- [1,128,129,255] -- [1,128,129,255] -- -- Using only -O1, we get the abnormal behavior again: -- [1] -- [1,128,129,255] }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13425 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13425: Semantically-equivalent expressions evaluating at different values with -O1 -------------------------------------+------------------------------------- Reporter: rbasso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): That is deeply strange. I have established * It happens with HEAD. * The combination of `-ffull-laziness` and `-fspec-constr` makes it produce the wrong answer `[1]`. Omitting either makes it give the right answer `[1,128,129,255]`. * Here are my command lines. I switched off everything I could. Failure case: {{{ simonpj@cam-05-unx:~/tmp$ ~/5builds/HEAD-5/inplace/bin/ghc-stage1 -dcore- lint -O2 -o T13425 T13425.hs -fforce-recomp -fno-enable-rewrite-rules -fno-liberate-case -fno-strictness -fno-cse -fno-call-arity -fno- specialise -fno-float-in -fno-late-dmd-anal [1 of 1] Compiling Main ( T13425.hs, T13425.o ) Linking T13425 ... simonpj@cam-05-unx:~/tmp$ ./T13425 [1] }}} Switch off full laziness (works) {{{ simonpj@cam-05-unx:~/tmp$ ~/5builds/HEAD-5/inplace/bin/ghc-stage1 -dcore- lint -O -o T13425 T13425.hs -fforce-recomp -fno-enable-rewrite-rules -fno- liberate-case -fno-strictness -fno-cse -fno-call-arity -fno-specialise -fno-float-in -fno-late-dmd-anal -fno-full-laziness [1 of 1] Compiling Main ( T13425.hs, T13425.o ) Linking T13425 ... simonpj@cam-05-unx:~/tmp$ ./T13425 [1,128,129,255] }}} Switch off spec-constr (works) {{{ simonpj@cam-05-unx:~/tmp$ ~/5builds/HEAD-5/inplace/bin/ghc-stage1 -dcore- lint -O -o T13425 T13425.hs -fforce-recomp -fno-enable-rewrite-rules -fno- liberate-case -fno-strictness -fno-cse -fno-call-arity -fno-specialise -fno-float-in -fno-late-dmd-anal -fno-spec-constr [1 of 1] Compiling Main ( T13425.hs, T13425.o ) Linking T13425 ... simonpj@cam-05-unx:~/tmp$ ./T13425 [1,128,129,255] }}} I'm out the rest of today. This is a bad bug; might someone look? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13425#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13425: Semantically-equivalent expressions evaluating at different values with -O1 -------------------------------------+------------------------------------- Reporter: rbasso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): I'll take a peek today. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13425#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13425: Semantically-equivalent expressions evaluating at different values with -O1 -------------------------------------+------------------------------------- Reporter: rbasso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * cc: dfeuer (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13425#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13425: Semantically-equivalent expressions evaluating at different values with -O1 -------------------------------------+------------------------------------- Reporter: rbasso | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Reid thinks he's found the ultimate source, in an optimization he made intended to help with tag bit checks. Here's a greatly reduced reproduction case: {{{#!hs import Data.Bits ((.&.)) flags :: Int -> Int flags x | x .&. 128 > 0 = 12 | otherwise = 13 {-# NOINLINE flags #-} main :: IO () main = print (flags 255) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13425#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13425: Semantically-equivalent expressions evaluating at different values with -O1 -------------------------------------+------------------------------------- Reporter: rbasso | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3359 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * status: new => patch * differential: => Phab:D3359 * milestone: => 8.2.1 Comment: Yep, sorry about that! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13425#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13425: Semantically-equivalent expressions evaluating at different values with -O1
-------------------------------------+-------------------------------------
Reporter: rbasso | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone: 8.2.1
Component: Compiler | Version: 8.0.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect result | Unknown/Multiple
at runtime | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3359
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13425: Semantically-equivalent expressions evaluating at different values with -O1 -------------------------------------+------------------------------------- Reporter: rbasso | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.0.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3359 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * priority: normal => high * resolution: => fixed Comment: Merged to `ghc-8.2` as bdb0c43c7991da3856e3a89db57c9ea78d61f55f. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13425#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC