[GHC] #10148: Optimization causes repeated computation
GHC
ghc-devs at haskell.org
Mon Mar 16 12:18:14 UTC 2015
#10148: Optimization causes repeated computation
-------------------------------------+-------------------------------------
Reporter: akio | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.1-rc1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by akio):
It looks like the simplifier does not preserve correctness of demand
information.
After the worker-wrapper pass, I have this fragment of code
{{{
of m'_axp [Dmd=<L,U(U(U))>] { Array ipv_s1i9 [Dmd=<L,A>] ->
Main.Machine (gstep m'_axp) t_axr
}
}}}
Here, the demand info on `ipv_s1i9` is correct, it is indeed unused.
However, after one iteration of simplifier pass, it becomes:
{{{
of m'_axp [Dmd=<L,U(U(U))>] { Array ipv_s1i9 [Dmd=<L,A>] ->
(# \ (w_s3Ix :: Int) ->
case w_s3Ix of _ [Occ=Dead] { GHC.Types.I# ww_X3IZ ->
case $wgstep_s3II ipv_s1i9 ww_X3IZ
of _ [Occ=Dead] { (# ww_X3Ja, ww_X3Jc #) ->
Main.Machine ww_X3Ja ww_X3Jc
}
},
ww_s3IA #)
}}}
Now `ipv_s1i9` is referenced and will be used, but its usage information
has not been updated.
I've found the note `[Case alternative occ info]` in Simplify.hs, which
explains why the occurrence info on case-bound variables should be zapped.
I tried zapping the usage info as well as the occurrence info here (patch
attached). It seems to compile `repeated2.hs` fine, but I'm not sure about
a few points:
* Is the approach right? i.e. is it a good idea to manually modify the
usage info in the simplifier?
* Probably the patch is overly conservative, in that it zaps the
strictness info as well as the usage info. However, how hard should I try
to preserve information? For example, should the code have a special case
for when the case binder and the scrutinee are both marked unused?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10148#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list