[GHC] #8317: Optimize tagToEnum# at Core level
#8317: Optimize tagToEnum# at Core level ------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #6135 | ------------------------------------+------------------------------------- Old comparison primops that returned Bool were implemented by inserting call to `tagToEnum#` in the code generator. This call to `tagToEnum#` was later optimized away by a special case in the code geenrator (see [[GhcFile(compiler/codeGen/StgCmmExpr.hs)]], Note [case on bool])). Now that we have new comparison primops (see #6135) we no longer insert `tagToEnum#` in the code generator - all uses of `tagToEnum#` come from explicit calls in a source program. But we still have that special case in the code generator to optimize away `tagToEnum#`. We should drop that special case in the code generator and handle scrutinizing of `tagToEnum#` at the Core level by: 1. removing call to `tagToEnum#` in the scrutinee 2. adding calls to `dataToTag#` in case branches 3. constant-folding inserted `dataToTag#` Here is an example. This Haskell code: {{{ if tagToEnum# (a ># b) then E1 else E2 }}} will be translated to this Core: {{{ case tagToEnum# (a ># b) of True -> E1 False -> E2 }}} and optimized like this: {{{ case a ># b of dataToTag# True -> E1 dataToTag# False -> E2 }}} ====> {{{ case a ># b of 1 -> E1 0 -> E2 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8317: Optimize tagToEnum# at Core level -------------------------------------+------------------------------------ Reporter: jstolarek | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: 8326 Blocking: | Related Tickets: #6135 -------------------------------------+------------------------------------ Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:62c405854afbeb6dabdaf5c737a2d7f625a2b3cb/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="62c405854afbeb6dabdaf5c737a2d7f625a2b3cb" Optimise (case tagToEnum# x of ..) as in Trac #8317 See Note [Optimising tagToEnum#] in Simplify }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8317: Optimize tagToEnum# at Core level -------------------------------------+------------------------------------ Reporter: jstolarek | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: 8326 Blocking: | Related Tickets: #6135 -------------------------------------+------------------------------------ Comment (by Jan Stolarek <jan.stolarek@…>): In [changeset:53948f915140396acd1b80c6a7a252b2d1e12635/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="53948f915140396acd1b80c6a7a252b2d1e12635" Restore old names of comparison primops In 6579a6c we removed existing comparison primops and introduced new ones returning Int# instead of Bool. This commit (and associated commits in array, base, dph, ghc-prim, integer-gmp, integer-simple, primitive, testsuite and template-haskell) restores old names of primops. This allows us to keep our API cleaner at the price of not having backwards compatibility. This patch also temporalily disables fix for #8317 (optimization of tagToEnum# at Core level). We need to fix #8326 first, otherwise our primops code will be very slow. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8317: Optimize tagToEnum# at Core level -------------------------------------+------------------------------------ Reporter: jstolarek | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: 8326 Blocking: | Related Tickets: #6135 -------------------------------------+------------------------------------ Comment (by jstolarek): Simon's fix is temporalily commented out, until we solve #8326. Once we've done that we have to uncomment the code. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8317: Optimize tagToEnum# at Core level -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: 8326 None/Unknown | Related Tickets: #6135 Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by jstolarek): * owner: => jstolarek -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8317: Optimize tagToEnum# at Core level -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: 8326 None/Unknown | Related Tickets: #6135 Test Case: | Blocking: | Differential Revisions: D343 | -------------------------------------+------------------------------------- Changes (by jstolarek): * differential: => D343 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8317: Optimize tagToEnum# at Core level -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: 8326 None/Unknown | Related Tickets: #6135 Test Case: | Blocking: | Differential Revisions: Phab:D343 | -------------------------------------+------------------------------------- Changes (by jstolarek): * differential: D343 => Phab:D343 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8317: Optimize tagToEnum# at Core level -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: 8326 | Test Case: Related Tickets: #6135 | Blocking: | Differential Revisions: Phab:D343 -------------------------------------+------------------------------------- Changes (by jstolarek): * owner: jstolarek => -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8317: Optimize tagToEnum# at Core level -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: datacon-tags Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: 8326 | Blocking: Related Tickets: #6135 | Differential Rev(s): Phab:D343 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * keywords: => datacon-tags -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8317#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC