[commit: ghc] master: Enhanced constant folding (fea04de)

git at git.haskell.org git at git.haskell.org
Fri Apr 13 22:07:36 UTC 2018


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

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

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

commit fea04defa64871caab6339ff3fc5511a272f37c7
Author: Sylvain Henry <hsyl20 at gmail.com>
Date:   Fri Apr 13 13:29:07 2018 -0400

    Enhanced constant folding
    
    Until now GHC only supported basic constant folding (lit op lit, expr op
    0, etc.).
    
    This patch uses laws of +/-/* (associativity, commutativity,
    distributivity) to support some constant folding into nested
    expressions.
    
    Examples of new transformations:
    
       - simple nesting: (10 + x) + 10 becomes 20 + x
       - deep nesting: 5 + x + (y + (z + (t + 5))) becomes 10 + (x + (y + (z + t)))
       - distribution: (5 + x) * 6 becomes 30 + 6*x
       - simple factorization: 5 + x + (x + (x + (x + 5))) becomes 10 + (4 *x)
       - siblings: (5 + 4*x) - (3*x + 2) becomes 3 + x
    
    Test Plan: validate
    
    Reviewers: simonpj, austin, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: thomie
    
    GHC Trac Issues: #9136
    
    Differential Revision: https://phabricator.haskell.org/D2858


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

fea04defa64871caab6339ff3fc5511a272f37c7
 compiler/main/DynFlags.hs                          |   3 +
 compiler/prelude/PrelRules.hs                      | 305 ++++++++++++++++++++-
 .../simplCore/should_compile/spec-inline.stderr    |  38 +--
 3 files changed, 309 insertions(+), 37 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 fea04defa64871caab6339ff3fc5511a272f37c7


More information about the ghc-commits mailing list