[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

#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

#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