Fix a small Float-Out bug
authorSimon Peyton Jones <simonpj@microsoft.com>
Wed, 26 Apr 2017 16:43:24 +0000 (17:43 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Tue, 2 May 2017 08:00:14 +0000 (09:00 +0100)
commitff239787f7170a93f1015bd0f5582772b7b87f0a
treebbc2614bb72f76b85b075afdbc2a797113c3bedf
parent71037b61597d8e80ba5acebc8ad2295e5266dc07
Fix a small Float-Out bug

The float-out pass uses a heuristic based on strictness info.
But it was getting the strictness info mis-aligned; I'd forgotten
that strictness flags only apply to /value/ arguments.

This patch fixes it.  It has some surprising effects!

--------------------------------------------------------------------------------
        Program           Size    Allocs   Runtime   Elapsed  TotalMem
--------------------------------------------------------------------------------
        integer          -0.1%     +9.9%     +0.2%     +0.2%     +0.0%
           lcss          +0.0%     +0.0%    -11.9%    -11.9%     +0.0%
         queens          -0.2%    +29.0%      0.02      0.02     +0.0%
         simple          -0.1%    -22.6%    -21.7%    -21.7%     -3.6%
       treejoin          +0.0%     +0.0%    -12.3%    -12.6%     +0.0%
--------------------------------------------------------------------------------
            Min          -0.2%    -22.6%    -21.7%    -21.7%    -10.0%
            Max          +3.3%    +29.0%    +19.2%    +19.2%    +50.0%
 Geometric Mean          +0.0%     +0.1%     -2.1%     -2.1%     +0.2%

The 'queens' and 'integer' allocation regressions are because, just
before let-floatting, we get
    \v -> foldr k z (case x of I# y -> build ..y..)

Becase of Note [Case MFEs] we don't float the build; so fusion
happens.  This increases allocation in queens because the build
isn't shared; but actaully runtime improves solidly.  Situation
is similar in integer, although I think runtime gets a bit worse.

The bug meant that, because of foldr's type arguments, the
mis-aligned strictness info meant that the entire (case x ...)
was floated, so fusion failed, but sharing happened.

This is all very artificial-benchmark-ish so I'm not losing sleep
over it.

I did see some runtime numbers increasd, but I think it's noise;
the differnce went away when I tried them one by one afterwards.
compiler/simplCore/SetLevels.hs