[GHC] #14684: combineIdenticalAlts is only partially implemented
GHC
ghc-devs at haskell.org
Thu Jan 18 23:27:44 UTC 2018
#14684: combineIdenticalAlts is only partially implemented
-------------------------------------+-------------------------------------
Reporter: mpickering | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.2
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 simonpj):
In `CoreUtils`, `Note [Combine identical alternatives]` acknowledges this
problem, saying
{{{
To avoid an expensive test, we just merge branches equal to the *first*
alternative; this picks up the common cases
a) all branches equal
b) some branches equal to the DEFAULT (which occurs first)
}}}
And indeed you are right that it'd be better to combine
{{{
foo x = case x of ==> foo x = case x of
A -> 0 DEFAULT -> 2
B -> 1 A -> 0
C -> 2 B -> 1
D -> 2
}}}
(Reminder: in Core the DEFAULT alternative always comes first, if it
exists.)
Fortunately, we now have `TrieMap.CoreMap`, an efficient finite map whose
keys are `CoreExprs`. Using this I think we can efficiently ask (as we
iterate oover the alternatives) "have I seen this RHS in an earlier
alternative?". More advanced: find the RHS that occurs most often. Take
care that in the common case the RHSs are (a) large and (b) different,
then the test does not exhaustively traverse the RHSs; just looks far
enough to establish they are different.
This a nice well-contained task, if someone would like to have a go.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14684#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list