Scrutinee Constant Folding
authorSylvain Henry <sylvain@haskus.fr>
Fri, 9 Dec 2016 15:26:34 +0000 (10:26 -0500)
committerBen Gamari <ben@smart-cactus.org>
Fri, 9 Dec 2016 15:27:34 +0000 (10:27 -0500)
commitd3b546b1a6058f26d5659c7f2000a7b25b7ea2ba
tree96929e66f77af1c5f9ce451c032a24e988de57b3
parent61932cd3eb0d5d22cb35d118fb9f87298881cd77
Scrutinee Constant Folding

This patch introduces new rules to perform constant folding through
case-expressions.

E.g.,
```
case t -# 10# of _ {  ===> case t of _ {
         5#      -> e1              15#     -> e1
         8#      -> e2              18#     -> e2
         DEFAULT -> e               DEFAULT -> e
```

The initial motivation is that it allows "Merge Nested Cases"
optimization to kick in and to further simplify the code
(see Trac #12877).

Currently we recognize the following operations for Word# and Int#: Add,
Sub, Xor, Not and Negate (for Int# only).

Test Plan: validate

Reviewers: simonpj, austin, bgamari

Reviewed By: simonpj, bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2762

GHC Trac Issues: #12877
compiler/basicTypes/Literal.hs
compiler/main/DynFlags.hs
compiler/prelude/PrelRules.hs
compiler/simplCore/SimplUtils.hs
docs/users_guide/using-optimisation.rst
testsuite/tests/perf/compiler/T12877.hs [new file with mode: 0644]
testsuite/tests/perf/compiler/T12877.stdout [new file with mode: 0644]
testsuite/tests/perf/compiler/all.T
utils/mkUserGuidePart/Options/Optimizations.hs