... |
... |
@@ -701,9 +701,9 @@ lvlMFE env strict_ctxt ann_expr |
701
|
701
|
|
702
|
702
|
-- See Note [Saving work]
|
703
|
703
|
is_hnf = exprIsHNF expr
|
704
|
|
- saves_work = escapes_value_lam -- (a)
|
705
|
|
- && not is_hnf -- (b)
|
706
|
|
- && not float_is_new_lam -- (c)
|
|
704
|
+ saves_work = escapes_value_lam -- (SW-a)
|
|
705
|
+ && not is_hnf -- (SW-b)
|
|
706
|
+ && not float_is_new_lam -- (SW-c)
|
707
|
707
|
escapes_value_lam = dest_lvl `ltMajLvl` (le_ctxt_lvl env)
|
708
|
708
|
|
709
|
709
|
-- See Note [Floating to the top]
|
... |
... |
@@ -728,19 +728,19 @@ Doing so can save an unbounded amount of work. |
728
|
728
|
But see also Note [Floating to the top].
|
729
|
729
|
|
730
|
730
|
So we definitely float an expression out if
|
731
|
|
-(a) It will escape a value lambda (escapes_value_lam)
|
732
|
|
-(b) The expression is not a head-normal form (exprIsHNF); see (SW1, SW2).
|
733
|
|
-(c) Floating does not require wrapping it in value lambdas (float_is_new_lam).
|
|
731
|
+(SW-a) It will escape a value lambda (escapes_value_lam)
|
|
732
|
+(SW-b) The expression is not a head-normal form (exprIsHNF); see (SW1, SW2).
|
|
733
|
+(SW-c) Floating does not require wrapping it in value lambdas (float_is_new_lam).
|
734
|
734
|
See (SW3) below
|
735
|
735
|
|
736
|
736
|
Wrinkles:
|
737
|
737
|
|
738
|
|
-(SW1) Concerning (b) I experimented with using `exprIsCheap` rather than
|
|
738
|
+(SW1) Concerning (SW-b) I experimented with using `exprIsCheap` rather than
|
739
|
739
|
`exprIsHNF` but the latter seems better, according to nofib
|
740
|
740
|
(`spectral/mate` got 10% worse with exprIsCheap). It's really a bit of a
|
741
|
741
|
heuristic.
|
742
|
742
|
|
743
|
|
-(SW2) What about omitting (b), and hence floating HNFs as well? The danger of
|
|
743
|
+(SW2) What about omitting (SW-b), and hence floating HNFs as well? The danger of
|
744
|
744
|
doing so is that we end up floating out a HNF from a cold path (where it
|
745
|
745
|
might never get allocated at all) and allocating it all the time
|
746
|
746
|
regardless. Example
|
... |
... |
@@ -759,7 +759,7 @@ Wrinkles: |
759
|
759
|
- Occasionally decreases runtime allocation (T12996 -2.5%)
|
760
|
760
|
- Slightly mixed effect on nofib: (puzzle -10%, mate -5%, cichelli +5%)
|
761
|
761
|
but geometric mean is -0.09%.
|
762
|
|
- Overall, a win.
|
|
762
|
+ Overall, a small win.
|
763
|
763
|
|
764
|
764
|
(SW3) Concerning (c), if we are wrapping the thing in extra value lambdas (in
|
765
|
765
|
abs_vars), then nothing is saved. E.g.
|