[Git][ghc/ghc][wip/T26722] Try using `uf_expandable` in `interestingArg`
Simon Peyton Jones pushed to branch wip/T26722 at Glasgow Haskell Compiler / GHC Commits: 2a7e8721 by Simon Peyton Jones at 2026-01-09T11:42:28+00:00 Try using `uf_expandable` in `interestingArg` See hmm in https://gitlab.haskell.org/ghc/ghc/-/issues/26722#note_652486 - - - - - 2 changed files: - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Core/Utils.hs Changes: ===================================== compiler/GHC/Core/Opt/Simplify/Utils.hs ===================================== @@ -1066,18 +1066,18 @@ interestingArg env e = go env 0 e DFunUnfolding {} -> ValueArg -- We konw that idArity=0 CoreUnfolding{ uf_cache = cache } | uf_is_conlike cache -> ValueArg -- Includes constructor applications - | uf_is_value cache -> NonTrivArg -- Things like partial applications + | uf_expandable cache -> NonTrivArg -- Things like partial applications, + -- and strict data constructors | otherwise -> TrivArg BootUnfolding -> TrivArg NoUnfolding -> TrivArg -************************************************************************ +{- ********************************************************************* * * SimplMode * * -************************************************************************ --} +********************************************************************* -} updModeForStableUnfoldings :: ActivationGhc -> SimplMode -> SimplMode -- See Note [The environments of the Simplify pass] ===================================== compiler/GHC/Core/Utils.hs ===================================== @@ -1509,6 +1509,22 @@ going to put up with this, because the previous more aggressive inlining (which treated 'noFactor' as work-free) was duplicating primops, which in turn was making inner loops of array calculations runs slow (#5623) +Wrinkles + +(WF1) Strict constructor fields. We regard (K x) as work-free even if + K is a strict data constructor (see Note [Strict fields in Core]) + data T a = K !a + If we have + let t = K x in ...(case t of K y -> blah)... + we want to treat t's binding as expandable so that `exprIsConApp_maybe` + will look through its unfolding. (NB: exprIsWorkFree implies + exprIsExpandable.) + + Because K is strict, after inlining we'll get a leftover eval on x, which may + or may not disappear + let t = K x in ...(case x of y -> blah)... + In effect we count duplicating the eval as work-free + Note [Case expressions are work-free] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Are case-expressions work-free? Consider @@ -1650,7 +1666,8 @@ isWorkFreeApp fn n_val_args = True | otherwise = case idDetails fn of - DataConWorkId {} -> True + DataConWorkId {} -> True -- Even if the data constructor is strict + -- See (WF1) in Note [exprIsWorkFree] PrimOpId op _ -> primOpIsWorkFree op _ -> False @@ -1751,6 +1768,8 @@ expansion. Specifically: duplicate the (a +# b) primop, which we should not do lightly. (It's quite hard to trigger this bug, but T13155 does so for GHC 8.0.) +NB: exprIsWorkFree implies exprIsExpandable. + Note [isExpandableApp: bottoming functions] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It's important that isExpandableApp does not respond True to bottoming View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2a7e8721ec12ce5e1eab32a92f58f5ef... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2a7e8721ec12ce5e1eab32a92f58f5ef... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Simon Peyton Jones (@simonpj)