#4943: Another odd missed SpecConstr opportunity
---------------------------------+------------------------------------------
    Reporter:  batterseapower    |       Owner:                         
        Type:  bug               |      Status:  new                    
    Priority:  normal            |   Component:  Compiler               
     Version:  7.1               |    Keywords:                         
    Testcase:                    |   Blockedby:                         
          Os:  Unknown/Multiple  |    Blocking:                         
Architecture:  Unknown/Multiple  |     Failure:  Runtime performance bug
---------------------------------+------------------------------------------
 Compiling the attached code with HEAD (and without case liberation) has
 this in the output of SpecConstr:

 {{{
 Rec {
 $wa_s1G0 [Occ=LoopBreaker]
   :: forall s_aIU.
      Data.Array.Base.STUArray s_aIU GHC.Types.Int GHC.Types.Int
      -> GHC.Types.Int
      -> GHC.Prim.Int#
      -> GHC.Prim.Int#
      -> GHC.Prim.State# s_aIU
      -> (# GHC.Prim.State# s_aIU, () #)
 [LclId, Arity=5, Str=DmdType LLLLL]
 $wa_s1G0 =
   \ (@ s_aIU)
     (w_s1FA
        :: Data.Array.Base.STUArray s_aIU GHC.Types.Int GHC.Types.Int)
     (w_s1FB :: GHC.Types.Int)
     (ww_s1FE :: GHC.Prim.Int#)
     (ww_s1FI :: GHC.Prim.Int#)
     (w_s1FK :: GHC.Prim.State# s_aIU) ->
     case GHC.Prim.># ww_s1FE ww_s1FI of wild_Xk [Dmd=Just A] {
       GHC.Types.False ->
         case w_s1FA
         of wild_aRL [Dmd=Just L]
         { Data.Array.Base.STUArray ds2_aRN [Dmd=Just U]
                                    ds3_aRO [Dmd=Just U]
                                    ds4_aRP [Dmd=Just U]
                                    marr#_aRQ [Dmd=Just L] ->
         case GHC.Prim.readIntArray# @ s_aIU marr#_aRQ ww_s1FE w_s1FK
         of wild2_aRX [Dmd=Just A]
         { (# s2#_aRZ [Dmd=Just L], e#_aS0 [Dmd=Just L] #) ->
         case w_s1FB
         of wild1_aSy [Dmd=Just L] { GHC.Types.I# y_aSA [Dmd=Just L] ->
         case GHC.Prim.writeIntArray#
                @ s_aIU marr#_aRQ ww_s1FE (GHC.Prim.+# e#_aS0 y_aSA)
 s2#_aRZ
         of s2#_aSp [Dmd=Just L] { __DEFAULT ->
         $wa_s1G0
           @ s_aIU w_s1FA w_s1FB (GHC.Prim.+# ww_s1FE 1) ww_s1FI s2#_aSp
         }
         }
         }
         };
       GHC.Types.True -> (# w_s1FK, GHC.Unit.() #)
     }
 end Rec }
 }}}

 i.e. we know the form of the first STUArray argument after the first
 iteration, but we leave it boxed and hence do the case every time around
 the loop.

 Is constructor specialisation not meant to hit this case? It seems so
 simple that I feel that this problem must come from my misunderstanding
 rather than a compiler error.

 Full command line:

 {{{
 ghc -fforce-recomp -c -dverbose-core2core -O2 -fno-liberate-case STUArray-
 Rewrite2.hs
 }}}

 (I disabled case liberation because I suspect it of having a bad effect
 elsewhere, but my understanding is that SpecConstr should still hit this
 case - IIRC all that CaseLib does that SpecConstr does not is deal with is
 hoisting case scrutinisation of the free variables of a function)

 Note that this is a GHC version *with* the patch "Improve Simplifier and
 SpecConstr behaviour". I can reproduce this with the GHC 7.0 RC as well.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to