[GHC] #13155: exprIsExpandable bug
#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
#13155: exprIsExpandable bug -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"9be18ea4e5cbc53ce7769a30275332d68a4ab6b9/ghc" 9be18ea/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="9be18ea4e5cbc53ce7769a30275332d68a4ab6b9" Fix a nasty bug in exprIsExpandable This bug has been lurking for ages: Trac #13155 The important semantic change is to ensure that exprIsExpandable returns False for primop calls. Previously exprIsExpandable used exprIsCheap' which always used primOpIsCheap. I took the opportunity to combine the code for exprIsCheap' (two variants: exprIsCheap and exprIsExpandable) with that for exprIsWorkFree. Result is simpler, tighter, easier to understand. And correct (at least wrt this bug)! }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13155#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13155: exprIsExpandable bug -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | simplCore/should_compile/T13155 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * testcase: => simplCore/should_compile/T13155 * resolution: => fixed Comment: It's hard to trigger this bug so probably not worth back-porting. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13155#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC