[GHC] #5075: CPR optimisation for sum types if only one constructor is used

GHC cvs-ghc at haskell.org
Thu Mar 7 01:27:12 CET 2013


#5075: CPR optimisation for sum types if only one constructor is used
---------------------------------+------------------------------------------
    Reporter:  batterseapower    |       Owner:  simonpj         
        Type:  feature request   |      Status:  patch           
    Priority:  normal            |   Milestone:  7.6.2           
   Component:  Compiler          |     Version:  7.0.3           
    Keywords:                    |          Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown    
  Difficulty:  Unknown           |    Testcase:                  
   Blockedby:                    |    Blocking:                  
     Related:                    |  
---------------------------------+------------------------------------------

Comment(by parcs):

 I noticed that sum CPR does not trigger for this function, when it seems
 like it should:

 {{{
 loop :: Int -> Maybe Int -> Maybe Int
 loop n x = case n of
     0 -> x
     _ -> loop (n-1) (fmap (+1) x)
 }}}

 The specializations that the SpecConstr pass creates for this function
 seem to be perfect candidates for sum CPR:

 {{{
 Rec {
 loop_$s$wloop
 loop_$s$wloop =
   \ sc_sop sc1_sor ->
     case sc_sop of ds_Xmj {
       __DEFAULT ->
         loop_$s$wloop
           (-# ds_Xmj 1) (case sc1_sor of _ { I# x_amE -> I# (+# x_amE 1)
 });
       0 -> Just sc1_sor
     }
 end Rec }

 Rec {
 loop_$s$wloop1
 loop_$s$wloop1 =
   \ sc_soq ->
     case sc_soq of ds_Xmj {
       __DEFAULT -> loop_$s$wloop1 (-# ds_Xmj 1);
       0 -> Nothing
     }
 end Rec }
 }}}

 Or am I mistaken?

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



More information about the ghc-tickets mailing list