[GHC] #13155: exprIsExpandable bug

GHC ghc-devs at haskell.org
Fri Jan 20 10:58:02 UTC 2017


#13155: exprIsExpandable bug
-------------------------------------+-------------------------------------
           Reporter:  simonpj        |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Consider this program, derived from T5623 (c.f. #5623)
 {{{
 {-# LANGUAGE MagicHash, UnboxedTuples #-}
 {-# OPTIONS_GHC -funfolding-use-threshold=10 #-}

 module T5623 where

 import GHC.Ptr
 import GHC.Prim
 import GHC.Exts

 foo :: Ptr Float -> State# RealWorld -> (# State# RealWorld, Float #)
 -- foo p = liftM2 (+) (peekElemOff q 0) (peekElemOff q 1)
 foo p s = case q :: Ptr Float of { Ptr a1 ->
           case readFloatOffAddr# a1 0# s of { (# s1, f1 #) ->
           case q :: Ptr Float of { Ptr a2 ->
           case readFloatOffAddr# a2 1# s of { (# s2, f2 #) ->
           (# s2, F# (plusFloat# f1 f2) #) }}}}
   where
     q :: Ptr a  -- Polymorphic
     q = p `plusPtr` 4
 }}}
 The `-funfolding-use-threshold=10` is important because it makes the
 worker/wrapper pass do a w/w split for `foo`.  (Otherwise it's too small
 for w/w.)

 The optimised core looks like
 {{{
 foo =
   \ (w_s2TO :: Ptr Float) (w1_s2TP :: State# RealWorld) ->
     case w_s2TO of { Ptr ww1_s2TS ->
     case readFloatOffAddr#
            @ RealWorld (plusAddr# ww1_s2TS 4#) 0# w1_s2TP
     of
     { (# ipv_s2ST, ipv1_s2SU #) ->
     case readFloatOffAddr#
            @ RealWorld (plusAddr# ww1_s2TS 4#) 1# w1_s2TP
     of
     { (# ipv2_s2SY, ipv3_s2SZ #) ->
     (# ipv2_s2SY, GHC.Types.F# (plusFloat# ipv1_s2SU ipv3_s2SZ) #)
     }    }    }
 }}}
 Yikes!  Look at that duplicated `plusAddr#`!

 It turned out to be a hard-to-trigger bug in `exprIsExpandable`.

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


More information about the ghc-tickets mailing list