[commit: ghc] master: Refactor the story around switches (#10137) (de1160b)

git at git.haskell.org git at git.haskell.org
Mon Mar 30 08:22:20 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/de1160be047790afde4ec76de0a81ba3be0c73fa/ghc

>---------------------------------------------------------------

commit de1160be047790afde4ec76de0a81ba3be0c73fa
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Mon Mar 30 10:20:14 2015 +0200

    Refactor the story around switches (#10137)
    
    This re-implements the code generation for case expressions at the Stg →
    Cmm level, both for data type cases as well as for integral literal
    cases. (Cases on float are still treated as before).
    
    The goal is to allow for fancier strategies in implementing them, for a
    cleaner separation of the strategy from the gritty details of Cmm, and
    to run this later than the Common Block Optimization, allowing for one
    way to attack #10124. The new module CmmSwitch contains a number of
    notes explaining this changes. For example, it creates larger
    consecutive jump tables than the previous code, if possible.
    
    nofib shows little significant overall improvement of runtime. The
    rather large wobbling comes from changes in the code block order
    (see #8082, not much we can do about it). But the decrease in code size
    alone makes this worthwhile.
    
    ```
            Program           Size    Allocs   Runtime   Elapsed  TotalMem
                Min          -1.8%      0.0%     -6.1%     -6.1%     -2.9%
                Max          -0.7%     +0.0%     +5.6%     +5.7%     +7.8%
     Geometric Mean          -1.4%     -0.0%     -0.3%     -0.3%     +0.0%
    ```
    
    Compilation time increases slightly:
    ```
            -1 s.d.                -----            -2.0%
            +1 s.d.                -----            +2.5%
            Average                -----            +0.3%
    ```
    
    The test case T783 regresses a lot, but it is the only one exhibiting
    any regression. The cause is the changed order of branches in an
    if-then-else tree, which makes the hoople data flow analysis traverse
    the blocks in a suboptimal order. Reverting that gets rid of this
    regression, but has a consistent, if only very small (+0.2%), negative
    effect on runtime. So I conclude that this test is an extreme outlier
    and no reason to change the code.
    
    Differential Revision: https://phabricator.haskell.org/D720


>---------------------------------------------------------------

de1160be047790afde4ec76de0a81ba3be0c73fa
 compiler/basicTypes/Literal.hs                     |  23 +-
 compiler/cmm/CmmCommonBlockElim.hs                 |   8 +-
 compiler/cmm/CmmContFlowOpt.hs                     |   3 +-
 compiler/cmm/CmmImplementSwitchPlans.hs            |  90 ++++
 compiler/cmm/CmmLint.hs                            |   6 +-
 compiler/cmm/CmmNode.hs                            |  16 +-
 compiler/cmm/CmmParse.y                            |  36 +-
 compiler/cmm/CmmPipeline.hs                        |   5 +
 compiler/cmm/CmmProcPoint.hs                       |   5 +-
 compiler/cmm/CmmSwitch.hs                          | 415 +++++++++++++++++
 compiler/cmm/CmmUtils.hs                           |  17 +-
 compiler/cmm/MkGraph.hs                            |   3 +-
 compiler/cmm/PprC.hs                               |  25 +-
 compiler/cmm/PprCmm.hs                             |  37 +-
 compiler/codeGen/StgCmmUtils.hs                    | 240 +++-------
 compiler/ghc.cabal.in                              |   2 +
 compiler/ghc.mk                                    |   1 +
 compiler/llvmGen/LlvmCodeGen/CodeGen.hs            |  15 +-
 compiler/main/DynFlags.hs                          |   2 +
 compiler/nativeGen/PPC/CodeGen.hs                  |  14 +-
 compiler/nativeGen/SPARC/CodeGen.hs                |  12 +-
 compiler/nativeGen/X86/CodeGen.hs                  |  14 +-
 .../tests/codeGen/should_run/CmmSwitchTest.hs      | 505 +++++++++++++++++++++
 .../tests/codeGen/should_run/CmmSwitchTestGen.hs   | 115 +++++
 testsuite/tests/codeGen/should_run/all.T           |   1 +
 testsuite/tests/perf/compiler/all.T                |   6 +-
 26 files changed, 1323 insertions(+), 293 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc de1160be047790afde4ec76de0a81ba3be0c73fa


More information about the ghc-commits mailing list