
#10626: Missed opportunity for SpecConstr
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by dsc):
* cc: dsc (added)
Comment:
(Not sure if my problem is different enough from this one to warrant a
separate ticket.)
I also have a problem where SpecConstr apparently gets stuck and doesn't
converge to a fixed point: If I translate the Core back into Haskell and
compile that again, I get great code with all state constructors
eliminated.
The code in question is TH-generated stream fusion code. I suppose that
only the dump-splices result is relevant here, so I made it compilable and
attached that (Input.hs).
The Core (also attached) contains lots of seemingly obvious SpecConstr
opportunities:
{{{
test_$s$wgfold_loop =
\ (sc
:: FlattenState
Int (ParamAndState Int (ConcatState YieldState ()
YieldState)))
(sc1 :: Int)
(sc2 :: Int#) ->
case sc1 of _ [Occ=Dead] { I# y ->
case sc of _ [Occ=Dead] {
[...]
Flatten_RunningInner so_agux si_aguy ->
[...]
test_$s$wgfold_loop
(Flatten_RunningInner
so_agux (ParamAndState a_aguz (CS_First
AfterYielding)))
a_aguz
(+# (+# sc2 y) 42#);
[...]
test_$s$wgfold_loop
(Flatten_RunningInner
so_agux (ParamAndState a_aguz (CS_Second ()
AfterYielding)))
a_aguz
(+# (+# sc2 y) 42#)
[...]
}}}
This is the second-round Core after retranslating the first Core into
Haskell (hopefully without changing semantics) and compiling again:
{{{
test_$s$wgfold_loop =
\ (sc :: Int#)
(sc1 :: Int#)
(sc2 :: Int#)
_ [Occ=Dead]
_ [Occ=Dead] ->
case tagToEnum# (># sc2 1000000#) of _ [Occ=Dead] {
False ->
test_$s$wgfold_loop
(+# (+# (+# (+# sc sc1) 42#) sc2) 42#) sc2 (+# sc2 1#) sc2 ();
True -> +# sc sc1
}
}}}
I noticed that in the first core, GHC thinks that `test_$s$wgfold_loop` is
lazy (`Str=DmdType