[GHC] #8317: Optimize tagToEnum# at Core level

GHC ghc-devs at haskell.org
Tue Sep 17 14:31:50 CEST 2013


#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



More information about the ghc-tickets mailing list