[GHC] #9136: Constant folding in Core could be better

GHC ghc-devs at haskell.org
Fri Apr 13 22:07:30 UTC 2018


#9136: Constant folding in Core could be better
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:  (none)
            Type:  bug               |               Status:  infoneeded
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.8.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D2858
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Ben Gamari <ben@…>):

 In [changeset:"fea04defa64871caab6339ff3fc5511a272f37c7/ghc" fea04de/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="fea04defa64871caab6339ff3fc5511a272f37c7"
 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
 }}}

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9136#comment:24>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list