[GHC] #14152: Float exit paths out of recursive functions

GHC ghc-devs at haskell.org
Fri Aug 25 12:20:04 UTC 2017


#14152: Float exit paths out of recursive functions
-------------------------------------+-------------------------------------
        Reporter:  nomeata           |                Owner:  (none)
            Type:  task              |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.1
      Resolution:                    |             Keywords:  JoinPoints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #14137 #10918     |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by nomeata):

 Note to myself:

 == Common up identical exit paths

 I expect much code to look like this:
 {{{
 let x = f x0
 joinrec go 0 = h x
         go 10 = h x
         go 30 = if something then h x     else call go (n-1)
         go 40 = if something then h (x+1) else call go (n-1)
         go n = call go (n-1)
 in call go 10
 }}}
 where a recursive function checks a bunch of conditions and has the same
 exit code multiple times. Ih would be silly to create three joint points
 with `h x` as the right hand side. So when floating out these exit
 expressions, I plan to check if the same expression is already being
 floated out and use that join point, to get

 {{{
 let x = f x0
 join exit1 = h x
 join exit2 = h (x+1)
 joinrec go 0 = call exit1
         go 10 = call exit1
         go 30 = if something then call exit1 else call go (n-1)
         go 40 = if something then call exit2 else call go (n-1)
         go n = call go (n-1)
 in call go 10
 }}}

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14152#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list