Commit b8f58d79 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Another improvement to SetLevels

In my recent commit
   commit 432f952e
   Float unboxed expressions by boxing
I changed how float_me in lvlMFE worked.  That was right, but
it exposed another bug: an error expression wasn't getting floated
as it should from a case alternative.  And that led to a collection
of minor improvements

* I found a much better way to cast it, by using lvlFloatRhs for
  top-level bindinds as well as nested ones, which is
    (a) more consistent and
    (b) works correctly.

  See Note [Floating from a RHS]

* I also found some delicacy in the "floating to the top" stuff, so I
  greatly elaborated the Note [Floating to the top].

* I simplified the "bottoming-float" stuff; the change is in the treatment
  of bottoming lambdas (\x y. error blah), where we now float the
  (error blah) part instead of the whole lambda (which risks just making
  duplicate lambdas.  See Note [Bottoming floats], esp (2).

Perf effects are minor.

* perf/compiler/T13056 improved sligtly (about 2%) in compiler
  allocations. Also T9233 improved by 1%.  I'm not sure why.

* Some small nofib changes:
    - Generally some very small reductions in run-time
      allocation, except k-nucleotide, which halves for some
      reason.  (I did try to look but it's a big complicated
      function and it was far from obvious.  Had it been a loss
      I would have looked harder!

NB: there's a nearby patch "Do not inline bottoming things" that could
also be responsible for either or both.  I didn't think it was worth
more testing to distinguish.

--------------------------------------------------------------------------------
        Program           Size    Allocs   Runtime   Elapsed  TotalMem
--------------------------------------------------------------------------------
           grep          +0.1%     -0.2%      0.00      0.00     +0.0%
         mandel          -0.1%     -1.4%      0.13      0.13     +0.0%
   k-nucleotide          +0.1%    -51.6%     -1.0%     -1.0%     +0.0%
--------------------------------------------------------------------------------
            Min          -0.3%    -51.6%     -9.4%     -9.1%     -4.0%
            Max          +0.2%     +0.0%    +31.8%    +32.7%     +0.0%
 Geometric Mean          -0.0%     -0.8%     +1.4%     +1.4%     -0.1%
parent f77e99bb
......@@ -1586,11 +1586,12 @@ don't want to discard a seq on it.
-}
-- | Can we bind this 'CoreExpr' at the top level?
exprIsTopLevelBindable :: CoreExpr -> Bool
exprIsTopLevelBindable :: CoreExpr -> Type -> Bool
-- See Note [CoreSyn top-level string literals]
exprIsTopLevelBindable expr
-- Precondition: exprType expr = ty
exprIsTopLevelBindable expr ty
= exprIsLiteralString expr
|| not (isUnliftedType (exprType expr))
|| not (isUnliftedType ty)
exprIsLiteralString :: CoreExpr -> Bool
exprIsLiteralString (Lit (MachStr _)) = True
......
This diff is collapsed.
......@@ -654,7 +654,7 @@ makeTrivialWithInfo :: TopLevelFlag -> SimplEnv
-- Returned SimplEnv has same substitution as incoming one
makeTrivialWithInfo top_lvl env context info expr
| exprIsTrivial expr -- Already trivial
|| not (bindingOk top_lvl expr) -- Cannot trivialise
|| not (bindingOk top_lvl expr expr_ty) -- Cannot trivialise
-- See Note [Cannot trivialise]
= return (env, expr)
| otherwise -- See Note [Take care] below
......@@ -676,11 +676,11 @@ makeTrivialWithInfo top_lvl env context info expr
where
expr_ty = exprType expr
bindingOk :: TopLevelFlag -> CoreExpr -> Bool
bindingOk :: TopLevelFlag -> CoreExpr -> Type -> Bool
-- True iff we can have a binding of this expression at this level
-- Precondition: the type is the type of the expression
bindingOk top_lvl expr
| isTopLevel top_lvl = exprIsTopLevelBindable expr
bindingOk top_lvl expr expr_ty
| isTopLevel top_lvl = exprIsTopLevelBindable expr expr_ty
| otherwise = True
{-
......
......@@ -608,7 +608,7 @@ test('T5837',
# 2014-12-08: 115905208 Constraint solver perf improvements (esp kick-out)
# 2016-04-06: 24199320 (x86/Linux, 64-bit machine) TypeInType
(wordsize(64), 57861352, 10)])
(wordsize(64), 50253880, 5)])
# sample: 3926235424 (amd64/Linux, 15/2/2012)
# 2012-10-02 81879216
# 2012-09-20 87254264 amd64/Linux
......@@ -634,6 +634,10 @@ test('T5837',
# compilation pipeline
# 2017-01-24 57861352 amd64/Linux, very likely due to the top-level strings
# in Core patch.
# 2017-02-07 50253880 Another improvement in SetLevels. I don't think
# all the gain here is from this patch, but I think it
# just pushed it over the edge, so I'm re-centreing, and
# changing to 5% tolerance
],
compile, ['-freduction-depth=50'])
......@@ -827,12 +831,16 @@ test('T9961',
test('T9233',
[ only_ways(['normal']),
compiler_stats_num_field('bytes allocated',
[(wordsize(64), 861862608, 5),
[(wordsize(64), 884436192, 5),
# 2015-08-04 999826288 initial value
# 2016-04-14 1066246248 Final demand analyzer run
# 2016-06-18 984268712 shuffling around of Data.Functor.Identity
# 2017-0123 861862608 worker/wrapper evald-ness flags; 10% improvement!
# 2017-01-20 920101608 Improvement to SetLevels apparently saved 4.2% in
# compiler allocation. Program size seems virtually
# unchanged; maybe the compiler itself is a little faster
# 2017-01-23 861862608 worker/wrapper evald-ness flags; another 5% improvement!
# 2017-02-01 894486272 Join points
# 2017-02-07 884436192 Another improvement to SetLevels
(wordsize(32), 515672240, 5) # Put in your value here if you hit this
# 2016-04-06 515672240 (x86/Linux) initial value
......@@ -942,9 +950,10 @@ test('T13035',
test('T13056',
[ only_ways(['optasm']),
compiler_stats_num_field('bytes allocated',
[(wordsize(64), 546800240, 5),
[(wordsize(64), 524611224, 5),
# 2017-01-06 520166912 initial
# 2017-01-31 546800240 Join points (#12988)
# 2017-02-07 524611224 new SetLevels
]),
],
compile,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment