[GHC] #9660: unnecessary indirect jump when returning a case scrutinee

GHC ghc-devs at haskell.org
Fri Oct 3 22:44:10 UTC 2014


#9660: unnecessary indirect jump when returning a case scrutinee
-------------------------------------+-------------------------------------
              Reporter:  rwbarton    |            Owner:
                  Type:  bug         |           Status:  new
              Priority:  normal      |        Milestone:
             Component:  Compiler    |          Version:  7.8.3
  (CodeGen)                          |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Unknown
  Unknown/Multiple                   |       Blocked By:
       Type of failure:  Runtime     |  Related Tickets:
  performance bug                    |
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------
Changes (by rwbarton):

 * cc: dfeuer (removed)


Comment:

 In fact it doesn't seem strictly necessary to add a new constructor to
 LambdaFormInfo... this proof-of-concept patch validates and produces the
 expected improved Cmm; nofib coming next...
 {{{
 diff --git a/compiler/codeGen/StgCmmClosure.hs
 b/compiler/codeGen/StgCmmClosure.hs
 index b65d56b..df0f6be 100644
 --- a/compiler/codeGen/StgCmmClosure.hs
 +++ b/compiler/codeGen/StgCmmClosure.hs
 @@ -22,7 +22,7 @@ module StgCmmClosure (
          LambdaFormInfo,         -- Abstract
          StandardFormInfo,        -- ...ditto...
          mkLFThunk, mkLFReEntrant, mkConLFInfo, mkSelectorLFInfo,
 -        mkApLFInfo, mkLFImported, mkLFArgument, mkLFLetNoEscape,
 +        mkApLFInfo, mkLFImported, mkLFArgument, mkLFLetNoEscape,
 mkLFUnknownCon,
          lfDynTag,
          maybeIsLFCon, isLFThunk, isLFReEntrant, lfUpdatable,

 @@ -241,6 +241,9 @@ mkLFThunk thunk_ty top fvs upd_flag
              NonStandardThunk
              (might_be_a_function thunk_ty)

 +mkLFUnknownCon :: LambdaFormInfo
 +mkLFUnknownCon = LFCon $ error "tried to access constructor of case
 binder at compile time"
 +
  --------------
  might_be_a_function :: Type -> Bool
  -- Return False only if we are *sure* it's a data type
 diff --git a/compiler/codeGen/StgCmmExpr.hs
 b/compiler/codeGen/StgCmmExpr.hs
 index b2b64f8..6b6ffef 100644
 --- a/compiler/codeGen/StgCmmExpr.hs
 +++ b/compiler/codeGen/StgCmmExpr.hs
 @@ -441,7 +441,11 @@ cgCase scrut bndr alt_type alts
         ; let sequel = AssignTo alt_regs do_gc{- Note [scrut sequel] -}
         ; ret_kind <- withSequel sequel (cgExpr scrut)
         ; restoreCurrentCostCentre mb_cc
 -       ; _ <- bindArgsToRegs ret_bndrs
 +       ; case alt_type of
 +           AlgAlt _ -> case ret_bndrs of
 +             [ret_bndr] -> void $ bindToReg ret_bndr mkLFUnknownCon
 +             _ -> error "wat"
 +           _ -> void $ bindArgsToRegs ret_bndrs
         ; cgAlts (gc_plan,ret_kind) (NonVoid bndr) alt_type alts
         }
 }}}

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


More information about the ghc-tickets mailing list