diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2022-11-14 17:40:01 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-01-12 15:51:47 -0500 |
commit | 905d0b6e1db714b306a940fb58a570c9294aa88d (patch) | |
tree | db8750594a94ad305f7f98fe87e7ccf8d2b17d6f /testsuite/tests/simplCore | |
parent | 9ffd5d57a7cc19bcd6ea0139b00c77639566ba82 (diff) | |
download | haskell-905d0b6e1db714b306a940fb58a570c9294aa88d.tar.gz |
Fix contification with stable unfoldings (#22428)
Many functions now return a `TailUsageDetails` that adorns a `UsageDetails` with
a `JoinArity` that reflects the number of join point binders around the body
for which the `UsageDetails` was computed. `TailUsageDetails` is now returned by
`occAnalLamTail` as well as `occAnalUnfolding` and `occAnalRules`.
I adjusted `Note [Join points and unfoldings/rules]` and
`Note [Adjusting right-hand sides]` to account for the new machinery.
I also wrote a new `Note [Join arity prediction based on joinRhsArity]`
and refer to it when we combine `TailUsageDetails` for a recursive RHS.
I also renamed
* `occAnalLam` to `occAnalLamTail`
* `adjustRhsUsage` to `adjustTailUsage`
* a few other less important functions
and properly documented the that each call of `occAnalLamTail` must pair up with
`adjustTailUsage`.
I removed `Note [Unfoldings and join points]` because it was redundant with
`Note [Occurrences in stable unfoldings]`.
While in town, I refactored `mkLoopBreakerNodes` so that it returns a condensed
`NodeDetails` called `SimpleNodeDetails`.
Fixes #22428.
The refactoring seems to have quite beneficial effect on ghc/alloc performance:
```
CoOpt_Read(normal) ghc/alloc 784,778,420 768,091,176 -2.1% GOOD
T12150(optasm) ghc/alloc 77,762,270 75,986,720 -2.3% GOOD
T12425(optasm) ghc/alloc 85,740,186 84,641,712 -1.3% GOOD
T13056(optasm) ghc/alloc 306,104,656 299,811,632 -2.1% GOOD
T13253(normal) ghc/alloc 350,233,952 346,004,008 -1.2%
T14683(normal) ghc/alloc 2,800,514,792 2,754,651,360 -1.6%
T15304(normal) ghc/alloc 1,230,883,318 1,215,978,336 -1.2%
T15630(normal) ghc/alloc 153,379,590 151,796,488 -1.0%
T16577(normal) ghc/alloc 7,356,797,056 7,244,194,416 -1.5%
T17516(normal) ghc/alloc 1,718,941,448 1,692,157,288 -1.6%
T19695(normal) ghc/alloc 1,485,794,632 1,458,022,112 -1.9%
T21839c(normal) ghc/alloc 437,562,314 431,295,896 -1.4% GOOD
T21839r(normal) ghc/alloc 446,927,580 440,615,776 -1.4% GOOD
geo. mean -0.6%
minimum -2.4%
maximum -0.0%
```
Metric Decrease:
CoOpt_Read
T10421
T12150
T12425
T13056
T18698a
T18698b
T21839c
T21839r
T9961
Diffstat (limited to 'testsuite/tests/simplCore')
-rw-r--r-- | testsuite/tests/simplCore/should_compile/T22428.hs | 9 | ||||
-rw-r--r-- | testsuite/tests/simplCore/should_compile/T22428.stderr | 45 | ||||
-rw-r--r-- | testsuite/tests/simplCore/should_compile/all.T | 4 |
3 files changed, 58 insertions, 0 deletions
diff --git a/testsuite/tests/simplCore/should_compile/T22428.hs b/testsuite/tests/simplCore/should_compile/T22428.hs new file mode 100644 index 0000000000..02cccb7f3a --- /dev/null +++ b/testsuite/tests/simplCore/should_compile/T22428.hs @@ -0,0 +1,9 @@ +module T22428 where + +f :: Integer -> Integer -> Integer +f x y = go y + where + go :: Integer -> Integer + go 0 = x + go n = go (n-1) + {-# INLINE go #-} diff --git a/testsuite/tests/simplCore/should_compile/T22428.stderr b/testsuite/tests/simplCore/should_compile/T22428.stderr new file mode 100644 index 0000000000..48ea278ae0 --- /dev/null +++ b/testsuite/tests/simplCore/should_compile/T22428.stderr @@ -0,0 +1,45 @@ + +==================== Tidy Core ==================== +Result size of Tidy Core + = {terms: 32, types: 14, coercions: 0, joins: 1/1} + +-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} +T22428.f1 :: Integer +[GblId, + Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, + WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] +T22428.f1 = GHC.Num.Integer.IS 1# + +-- RHS size: {terms: 28, types: 10, coercions: 0, joins: 1/1} +f :: Integer -> Integer -> Integer +[GblId, + Arity=2, + Str=<SL><1L>, + Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, + WorkFree=True, Expandable=True, Guidance=IF_ARGS [0 0] 156 0}] +f = \ (x :: Integer) (y :: Integer) -> + joinrec { + go [InlPrag=INLINE (sat-args=1), Occ=LoopBreaker, Dmd=SC(S,L)] + :: Integer -> Integer + [LclId[JoinId(1)(Just [!])], + Arity=1, + Str=<1L>, + Unf=Unf{Src=StableUser, TopLvl=False, Value=True, ConLike=True, + WorkFree=True, Expandable=True, + Guidance=ALWAYS_IF(arity=1,unsat_ok=False,boring_ok=False)}] + go (ds :: Integer) + = case ds of wild { + GHC.Num.Integer.IS x1 -> + case x1 of { + __DEFAULT -> jump go (GHC.Num.Integer.integerSub wild T22428.f1); + 0# -> x + }; + GHC.Num.Integer.IP x1 -> + jump go (GHC.Num.Integer.integerSub wild T22428.f1); + GHC.Num.Integer.IN x1 -> + jump go (GHC.Num.Integer.integerSub wild T22428.f1) + }; } in + jump go y + + + diff --git a/testsuite/tests/simplCore/should_compile/all.T b/testsuite/tests/simplCore/should_compile/all.T index 4fd57c5301..1b25c1b00b 100644 --- a/testsuite/tests/simplCore/should_compile/all.T +++ b/testsuite/tests/simplCore/should_compile/all.T @@ -459,6 +459,10 @@ test('T22494', [grep_errmsg(r'case') ], compile, ['-O -ddump-simpl -dsuppress-un test('T22491', normal, compile, ['-O2']) test('T21476', normal, compile, ['']) test('T22272', normal, multimod_compile, ['T22272', '-O -fexpose-all-unfoldings -fno-omit-interface-pragmas -fno-ignore-interface-pragmas']) + +# go should become a join point +test('T22428', [grep_errmsg(r'jump go') ], compile, ['-O -ddump-simpl -dsuppress-uniques -dno-typeable-binds -dsuppress-unfoldings']) + test('T22459', normal, compile, ['']) test('T22623', normal, multimod_compile, ['T22623', '-O -v0']) test('T22662', normal, compile, ['']) |