Nested CPR light (#19398)
While fixing #19232, it became increasingly clear that the vestigial hack described in `Note [Optimistic field binder CPR]` is complicated and causes reboxing. Rather than make the hack worse, this patch gets rid of it completely in favor of giving deeply unboxed parameters the Nested CPR property. Example: ```hs f :: (Int, Int) -> Int f p = case p of (x, y) | x == y = x | otherwise = y ``` Based on `p`'s `idDemandInfo` `1P(1P(L),1P(L))`, we can see that both fields of `p` will be available unboxed. As a result, we give `p` the nested CPR property `1(1,1)`. When analysing the `case`, the field CPRs are transferred to the binders `x` and `y`, respectively, so that we ultimately give `f` the CPR property. I took the liberty to do a bit of refactoring: - I renamed `CprResult` ("Constructed product result result") to plain `Cpr`. - I Introduced `FlatConCpr` in addition to (now nested) `ConCpr` and and according pattern synonym that rewrites flat `ConCpr` to `FlatConCpr`s, purely for compiler perf reasons. - Similarly for performance reasons, we now store binders with a Top signature in a separate `IntSet`, see `Note [Efficient Top sigs in SigEnv]`. - I moved a bit of stuff around in `GHC.Core.Opt.WorkWrap.Utils` and introduced `UnboxingDecision` to replace the `Maybe DataConPatContext` type we used to return from `wantToUnbox`. - Since the `Outputable Cpr` instance changed anyway, I removed the leading `m` which we used to emit for `ConCpr`. It's just noise, especially now that we may output nested CPRs. Fixes #19398.
Showing
- compiler/GHC/Core/Opt/CprAnal.hs 139 additions, 76 deletionscompiler/GHC/Core/Opt/CprAnal.hs
- compiler/GHC/Core/Opt/WorkWrap.hs 2 additions, 2 deletionscompiler/GHC/Core/Opt/WorkWrap.hs
- compiler/GHC/Core/Opt/WorkWrap/Utils.hs 350 additions, 322 deletionscompiler/GHC/Core/Opt/WorkWrap/Utils.hs
- compiler/GHC/Data/Graph/UnVar.hs 1 addition, 1 deletioncompiler/GHC/Data/Graph/UnVar.hs
- compiler/GHC/Types/Cpr.hs 146 additions, 79 deletionscompiler/GHC/Types/Cpr.hs
- compiler/GHC/Types/Id/Make.hs 2 additions, 2 deletionscompiler/GHC/Types/Id/Make.hs
- testsuite/tests/cpranal/sigs/CaseBinderCPR.stderr 1 addition, 2 deletionstestsuite/tests/cpranal/sigs/CaseBinderCPR.stderr
- testsuite/tests/cpranal/sigs/T19232.stderr 0 additions, 1 deletiontestsuite/tests/cpranal/sigs/T19232.stderr
- testsuite/tests/cpranal/sigs/T19398.hs 32 additions, 0 deletionstestsuite/tests/cpranal/sigs/T19398.hs
- testsuite/tests/cpranal/sigs/T19398.stderr 8 additions, 0 deletionstestsuite/tests/cpranal/sigs/T19398.stderr
- testsuite/tests/cpranal/sigs/all.T 2 additions, 1 deletiontestsuite/tests/cpranal/sigs/all.T
- testsuite/tests/deSugar/should_compile/T2431.stderr 1 addition, 1 deletiontestsuite/tests/deSugar/should_compile/T2431.stderr
- testsuite/tests/numeric/should_compile/T7116.stdout 4 additions, 4 deletionstestsuite/tests/numeric/should_compile/T7116.stdout
- testsuite/tests/simplCore/should_compile/T13143.stderr 1 addition, 1 deletiontestsuite/tests/simplCore/should_compile/T13143.stderr
- testsuite/tests/simplCore/should_compile/T13543.stderr 2 additions, 2 deletionstestsuite/tests/simplCore/should_compile/T13543.stderr
- testsuite/tests/simplCore/should_compile/T3717.stderr 1 addition, 1 deletiontestsuite/tests/simplCore/should_compile/T3717.stderr
- testsuite/tests/simplCore/should_compile/T4930.stderr 1 addition, 1 deletiontestsuite/tests/simplCore/should_compile/T4930.stderr
- testsuite/tests/simplCore/should_compile/T7360.stderr 2 additions, 2 deletionstestsuite/tests/simplCore/should_compile/T7360.stderr
- testsuite/tests/simplCore/should_compile/spec-inline.stderr 2 additions, 2 deletionstestsuite/tests/simplCore/should_compile/spec-inline.stderr
- testsuite/tests/stranal/should_compile/T10694.stderr 1 addition, 1 deletiontestsuite/tests/stranal/should_compile/T10694.stderr
Loading
Please register or sign in to comment