[GHC] #11702: Constant folding on 'mod/Word' - incorrect result
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Prelude | Version: 7.10.3 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: -------------------------------------+------------------------------------- Compiling this with GHC 7.10.3 on both MacOS and Linux with '-O' producess results '5 0'. {{{#!hs module Main where testfn :: Word -> IO () testfn wseq = do print $ wseq `mod` 1 main = do testfn 5 print $ (5 :: Word) `mod` 1 }}} Changing type to Int produces correct result. It has probably something to do with compiler/prelude/PrelRules.hs - the rules for Int and Word differ. It seems to me that it should be optimized the same way, but the culprit seems to be the 'rightIdentityDynFlags onew' - that seems to be a clear bug (if it does what I think it does). {{{#!hs primOpRules nm IntRemOp = mkPrimOpRule nm 2 [ nonZeroLit 1 >> binaryLit (intOp2 rem) , leftZero zeroi , do l <- getLiteral 1 dflags <- getDynFlags guard (l == onei dflags) retLit zeroi , equalArgs >> retLit zeroi , equalArgs >> retLit zeroi ] primOpRules nm WordRemOp = mkPrimOpRule nm 2 [ nonZeroLit 1 >> binaryLit (wordOp2 rem) , rightIdentityDynFlags onew ] }}} I found it in different code where lots of inlining reduced some branch of code into this and produced wrong result. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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 bgamari): * priority: normal => highest * milestone: => 8.0.1 Comment: Seems like this is something we should get on top of before 8.0.1. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: bgamari Type: bug | Status: new Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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 bgamari): * owner: => bgamari -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: bgamari Type: bug | Status: patch Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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:D2004 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch * differential: => Phab:D2004 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: bgamari Type: bug | Status: patch Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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:D2004 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"3f60ce8751c860a2bd0ddbe87429136a9d97449b/ghc" 3f60ce8/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="3f60ce8751c860a2bd0ddbe87429136a9d97449b" Add regression test for #11702 Test Plan: Validate Reviewers: austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2002 GHC Trac Issues: #11702 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: bgamari Type: bug | Status: patch Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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:D2004 Wiki Page: | -------------------------------------+------------------------------------- Comment (by trommler): FWIW, T11702 passes unexpectedly on powerpc64. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: bgamari Type: bug | Status: patch Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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:D2004 Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Replying to [comment:5 trommler]:
FWIW, T11702 passes unexpectedly on powerpc64.
And on my Mac. And on [https://s3.amazonaws.com/archive.travis- ci.org/jobs/116645450/log.txt Travis]. (The framework failures there are my fault. Will be fixed in my next raft, due tomorrow.) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: bgamari Type: bug | Status: patch Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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:D2004 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"3ddfcc95cd41dac19c8f4d55e8fc03128b77b738/ghc" 3ddfcc95/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="3ddfcc95cd41dac19c8f4d55e8fc03128b77b738" PrelRules: Fix constant folding for WordRemOp Test Plan: Validate with testcase in D2002 Reviewers: austin, simonpj Reviewed By: simonpj Subscribers: simonpj, thomie Differential Revision: https://phabricator.haskell.org/D2004 GHC Trac Issues: #11702 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: bgamari Type: bug | Status: closed Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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:D2004 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed Comment: Merged to `ghc-8.0` as 630d07995a814f665531eaecf07dffe1298c6fd5. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11702: Constant folding on 'mod/Word' - incorrect result -------------------------------------+------------------------------------- Reporter: ondrap | Owner: bgamari Type: bug | Status: closed Priority: highest | Milestone: 8.0.1 Component: Prelude | Version: 7.10.3 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:D2004 Wiki Page: | -------------------------------------+------------------------------------- Comment (by hjarvi): On my x64 the given test case goes through without a problem on GHC7.10 and GHC8.0, but I find a more effective test case to be (produces "5 0" on GHC7.10.3 and GHC8.0.0.20160302. The correct result "0 0" is produced by GHC 7.6.3 and GHC 8.0.1.20160822): {{{ -- -*- haskell -*- module Main ( main ) where import Data.IORef import Data.Word main = do i <- newIORef (5 :: Word) >>= readIORef print $ i `mod` 1 print $ (5 :: Word) `mod` 1 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11702#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC