#4941: SpecConstr generates functions that do not use their arguments
---------------------------------+------------------------------------------
    Reporter:  simonpj           |        Owner:              
        Type:  task              |       Status:  new         
    Priority:  normal            |    Milestone:  _|_         
   Component:  Compiler          |      Version:  7.0.1       
    Keywords:                    |     Testcase:              
   Blockedby:                    |   Difficulty:              
          Os:  Unknown/Multiple  |     Blocking:              
Architecture:  Unknown/Multiple  |      Failure:  None/Unknown
---------------------------------+------------------------------------------
 Consider this function:
 {{{
 f :: Int -> (Bool,Bool) -> Bool -> Bool
 f 0 x     y = y
 f n (p,q) y = f (n-1) (p,q) q
 }}}
 `SpecConstr` does a reasonable job, but ends up with a function like this:
 {{{
 T4908a.f_$s$wf =
   \ (sc_sp4 :: GHC.Prim.Int#)
     (sc1_sp5 :: GHC.Types.Bool)
     (sc2_sp6 :: GHC.Types.Bool)
     (sc3_sp7 :: GHC.Types.Bool) ->
     case sc_sp4 of ds_Xom {
       __DEFAULT ->
         T4908a.f_$s$wf (GHC.Prim.-# ds_Xom 1) sc1_sp5 sc2_sp6 sc2_sp6;
       0 -> sc3_sp7
     }
 }}}
 Note that `sc1_sp5` is passed around the loop but never used.

 I had a quick go at trying to make `SpecConstr` cleverer, but absence info
 requires a fixpoint analysis, which the existing `ArgOcc` stuff doesn't
 do.  Nor can we rely on absence analysis from earlier in the compiler,
 because CSE invalidates it.

 A possibility would be to run strictness/absence analysis again after
 `SpecConstr`, which would pick this up.  I'm not sure what other
 consequences this would have.

 So there's an opportunity here, but I'm not sure how much it matters in
 practice.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to