[GHC] #16335: Make CPR Analysis more aggressive for inductive cases
GHC
ghc-devs at haskell.org
Mon Feb 18 17:14:11 UTC 2019
#16335: Make CPR Analysis more aggressive for inductive cases
-------------------------------------+-------------------------------------
Reporter: sgraf | Owner: (none)
Type: task | Status: new
Priority: normal | Milestone: ⊥
Component: Compiler | Version: 8.6.3
Resolution: | Keywords: CPRAnalysis
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 sgraf):
To expand on the "Return pattern specialisation" thing:
||=SpecConstr=||= CPR+WW =||
||Multiple specialisations||One specialisation||
||Looks at how much the definition scrutinises its arguments in ''any'' of
its case expressions||Looks at how deep the constructed products are in
''all'' its return branches (mostly since we only do one specialisation)||
||Compares that to how the function is called and only allows matching
specialisations (unless `-fspec-constr-keen`||Doesn't look at calls, but
only provides the most conservative specialisation anyway||
Put another way: If we allowed multiple specialisations, we could have the
following two specialisations, no reboxing happening (no promises made on
correctness):
{{{
Foo.$weval
= \ (w_s1cn :: Expr) ->
case w_s1cn of {
Lit dt_d11b -> case dt_d11b { I# ds_abcd -> ds_abcd };
Plus a_aXf b_aXg ->
case Foo.$weval a_aXf of ww_s1cq { __DEFAULT ->
case Foo.$weval b_aXg of ww1_X1dh { __DEFAULT ->
GHC.Prim.+# ww_s1cq ww1_X1dh
}
}
}
eval
= \ (ds_d112 :: Expr) ->
case ds_d112 of {
Lit n_aXf -> n_aXf;
Plus a_aXg b_aXh ->
case $weval a_aXg of { __DEFAULT ->
case $weval b_aXh of { __DEFAULT ->
GHC.Types.I# (GHC.Prim.+# a_aXg b_aXh)
}
}
}
}}}
Note that we were able to rewrite both inductive calls in terms of
`$weval`, but still have the vanilla version around if we ever need the
boxed result of `eval`.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16335#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list