exprIsExpandable bug
Consider this program, derived from T5623 (c.f. #5623 (closed))
{-# 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
.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |