[GHC] #12656: ghc floats out constant despite -fno-cse (was: ghci floats out constant despite -fno-cse)

GHC ghc-devs at haskell.org
Mon Oct 3 14:45:51 UTC 2016


#12656: ghc floats out constant despite -fno-cse
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      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:                    |
-------------------------------------+-------------------------------------
Description changed by nh2:

@@ -13,0 +13,2 @@
+
+   let f = foo 100000 in f >> f
@@ -47,1 +49,1 @@
- (Note: With `ghc` instead of `ghci`, we don't observe this behaviour.)
+ (Note: This also happens with `ghc` instead of `ghci`.)

New description:

 Consider this program using `Data.Vector.unsafeThaw` and `-fno-cse`:

 {{{
 {-# OPTIONS_GHC -fno-cse #-}

 import qualified Data.Vector as V
 import qualified Data.Vector.Mutable as VM

 main :: IO ()
 main = do
   foo 100000
   foo 100000

   let f = foo 100000 in f >> f

 foo :: Int -> IO ()
 foo n = do
   indexVector <- V.unsafeThaw $ V.generate n id

   x <- VM.read indexVector 5
   VM.write indexVector 5 (x * x)

   print x

 -- In GHCI, we get:
 --
 -- > :set -fno-cse
 --
 -- > foo 100000
 -- 5
 -- > foo 100000
 -- 5
 --
 -- > let f = foo 100000 in f >> f
 -- 5
 -- 25
 }}}

 I would expect that

 {{{
 > let f = foo 100000 in f >> f
 5
 5
 }}}

 Shouldn't `-fno-cse` fix this?

 (Note: This also happens with `ghc` instead of `ghci`.)

--

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


More information about the ghc-tickets mailing list