[GHC] #855: Improvements to SpecConstr

GHC ghc-devs at haskell.org
Wed Mar 28 14:11:18 UTC 2018


#855: Improvements to SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:  (none)
            Type:  task              |               Status:  new
        Priority:  normal            |            Milestone:  ⊥
       Component:  Compiler          |              Version:  6.4.2
      Resolution:                    |             Keywords:  SpecConstr
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:  N/A
      Blocked By:                    |             Blocking:  915
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by sgraf):

 A quick update: `ex1` is optimized to similar code as above, but without
 resorting to forced `SPEC` now. E.g., inference of `ArgOcc`s is now much
 better, because it looks at occs from specialised RHSs now (specialising
 for lambdas gives rise to new occs). This entailed a rewrite of the spec
 loop. Also I had to pass on occs from recursive calls to achieve something
 like the static argument transformation.

 I'll write things up in a wiki page once I'm done trying to optimize
 `ex{2,3}`. This is the code currently generated for `ex1`:

 {{{
 -- RHS size: {terms: 41, types: 23, coercions: 0, joins: 3/3}
 Main.$wex1 [InlPrag=NOINLINE] :: GHC.Prim.Int# -> GHC.Prim.Int#
 [GblId, Arity=1, Caf=NoCafRefs, Str=<S,U>, Unf=OtherCon []]
 Main.$wex1
   = \ (ww_s4m8 :: GHC.Prim.Int#) ->
       joinrec {
         $s$wgo_s4or
           :: GHC.Prim.Int#
              -> GHC.Prim.Int# -> GHC.Prim.Int# -> Bool -> GHC.Prim.Int#
         [LclId[JoinId(4)], Arity=4, Str=<S,U><S,U><L,A><L,A>]
         $s$wgo_s4or (sc_s4oq :: GHC.Prim.Int#)
                     (sc1_s4op :: GHC.Prim.Int#)
                     _ [Occ=Dead]
                     _ [Occ=Dead]
           = jump $s$wgo2_s4nk sc1_s4op sc_s4oq;
         $s$wgo1_s4o0
           :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int# ->
 GHC.Prim.Int#
         [LclId[JoinId(3)], Arity=3, Str=<S,U><S,U><S,U>]
         $s$wgo1_s4o0 (sc_s4nZ :: GHC.Prim.Int#)
                      (sc1_s4nY :: GHC.Prim.Int#)
                      (sc2_s4nX :: GHC.Prim.Int#)
           = jump $s$wgo_s4or
               (GHC.Prim.+# sc2_s4nX sc_s4nZ) sc1_s4nY sc_s4nZ
 GHC.Types.False;
         $s$wgo2_s4nk [Occ=LoopBreaker]
           :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int#
         [LclId[JoinId(2)], Arity=2, Str=<S,U><S,U>, Unf=OtherCon []]
         $s$wgo2_s4nk (sc_s4nj :: GHC.Prim.Int#) (sc1_s4ni ::
 GHC.Prim.Int#)
           = case GHC.Prim.<# sc_s4nj ww_s4m8 of {
               __DEFAULT -> sc1_s4ni;
               1# ->
                 jump $s$wgo1_s4o0
                   (GHC.Prim.*# sc_s4nj sc_s4nj) (GHC.Prim.+# sc_s4nj 1#)
 sc1_s4ni
             }; } in
       jump $s$wgo2_s4nk 1# 0#
 }}}

 `-flate-dmd-anal` gets rid of the superfluous `$s$wgo_s4or`, but what pass
 is responsible for contracting the recursive group into a single binding
 (by inlining until we hit the loopbreaker)?

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


More information about the ghc-tickets mailing list