[GHC] #13397: Optimise calls to tagToEnum#

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Ever since we started using `Int#` to represent booleans unboxed (see [wiki:PrimBool]) we have had lots of code looking like {{{ case tagToEnum# (a ># b) of False -> e1 True -> e2 }}} It would be better (less code to optimise, more straightforward, more direct) to optimise this to {{{ case a ># b of DEFAULT -> e1 1# -> e2 }}} Happily, we already have a nice spot to do so: the `caseRules` function in `SimplUtils`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum#
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
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):
I have committed these patches to branch `wip/spj-T13397`:
{{{
commit 43540c8c6b9e914f302c71213a71ab5c780be2ac
Author: Simon Peyton Jones

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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): PS The improvement in `cryptarithm1` runtime appears to be solid and real too. So there is a win here! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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: | -------------------------------------+------------------------------------- Changes (by rwbarton): * Attachment "nofib" added. normal nofib output -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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: | -------------------------------------+------------------------------------- Changes (by rwbarton): * Attachment "nofib.slow" added. slow nofib output -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 rwbarton): I got rather different results from nofib, attached above. Note that these are for a full recompilation from scratch. Judging from the Size column in your nofib output, I guess that you probably also did a full recompilation from scratch. In the program that regressed the most in my nofib run, tak, it looks like the code generator just output basic blocks in a different order. Probably the order of the `then` and `else` branches of a conditional got reversed. tak is known to be very sensitive to (poorly-understood) alignment effects (#8279) so I'm inclined to assume this is just noise that we can't do much about. Not really sure what to make of the larger regressions that you saw, or why I can't reproduce them. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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): Hmm. I can re-try. Did you see any wins either? What does your summary table (like the above) look like? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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): I found another reason to do this: `tagToEnum# (x ># y)` is floated out by full laziness, creating a new thunk and a free variable of the function closure. But plain `(x ># y)` is not: it's too cheap to be worth it. We could make `tagToEnum# (x ># y)` look cheaper, but if we eliminate it we don't have to bother. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 dfeuer): Simon, I rebased your branch and fixed a comment, producing `wip/dfeuer-T13397`. The [https://perf.haskell.org/ghc/#compare/583fa9e3687b49d8c779e6d53a75af9276e4f5... perf results] generally look fine, with a few very small regressions: {{{ Nofib allocations ----------------- knights +1.35% pic +1.14% scs +0.81% (this ran slightly *faster*) last-piece +0.29% Nofib runtimes -------------- cacheprof +1.3% last-piece +1.23% hidden +1.08% wheel-sieve1 +0.95% digits-of-e1 +0.87% lambda +0.47% Test suite allocations ---------------------- T783 +0.59% T9675 +0.33% T12707 +0.23% }}} The wins seem modest, but bigger than the regressions: {{{ Nofib allocations ----------------- anna -0.7% fft -0.41% Nofib runtimes -------------- cryptarithm1 -4.29% fannkuch-redux -3.75% binary-trees -3.7% scs -1.28% integer -1% fasta -0.98% mate -0.95% digits-of-e2 -0.85% }}} As far as I'm concerned, this should probably be ready to merge. Should I do so? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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: | -------------------------------------+------------------------------------- Changes (by dfeuer): * cc: dfeuer (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 principle yes. But although +0.59% allocation in T783, say isn't important enough to prevent using is, it'd be good to know why it happened. Maybe there's something simple going wrong that would be easily fixed? Or maybe it's one of those things like "with the change, f becomes small enough to inline into g, so g becomes too big to inline at its call sites and that makes the difference". If so, fine. But it'd be good to know. I find `-ticky` lets you nail the changes really fast. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum#
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
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 David Feuer

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: datacon-tags Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * keywords: => datacon-tags -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum#
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords: datacon-tags
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 dfeuer):
Simon's `caseRules` re-engineering was merged in
193664d42dbceadaa1e4689dfa17ff1cf5a405a0
{{{
commit 193664d42dbceadaa1e4689dfa17ff1cf5a405a0
Author: Simon Peyton Jones

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: datacon-tags 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 dfeuer): It's not clear to me what remains to be done on this ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13397: Optimise calls to tagToEnum# -------------------------------------+------------------------------------- Reporter: simonpj | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: datacon-tags Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13397#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC