| ... |
... |
@@ -1509,6 +1509,22 @@ going to put up with this, because the previous more aggressive inlining |
|
1509
|
1509
|
(which treated 'noFactor' as work-free) was duplicating primops, which
|
|
1510
|
1510
|
in turn was making inner loops of array calculations runs slow (#5623)
|
|
1511
|
1511
|
|
|
|
1512
|
+Wrinkles
|
|
|
1513
|
+
|
|
|
1514
|
+(WF1) Strict constructor fields. We regard (K x) as work-free even if
|
|
|
1515
|
+ K is a strict data constructor (see Note [Strict fields in Core])
|
|
|
1516
|
+ data T a = K !a
|
|
|
1517
|
+ If we have
|
|
|
1518
|
+ let t = K x in ...(case t of K y -> blah)...
|
|
|
1519
|
+ we want to treat t's binding as expandable so that `exprIsConApp_maybe`
|
|
|
1520
|
+ will look through its unfolding. (NB: exprIsWorkFree implies
|
|
|
1521
|
+ exprIsExpandable.)
|
|
|
1522
|
+
|
|
|
1523
|
+ Because K is strict, after inlining we'll get a leftover eval on x, which may
|
|
|
1524
|
+ or may not disappear
|
|
|
1525
|
+ let t = K x in ...(case x of y -> blah)...
|
|
|
1526
|
+ In effect we count duplicating the eval as work-free
|
|
|
1527
|
+
|
|
1512
|
1528
|
Note [Case expressions are work-free]
|
|
1513
|
1529
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1514
|
1530
|
Are case-expressions work-free? Consider
|
| ... |
... |
@@ -1650,7 +1666,8 @@ isWorkFreeApp fn n_val_args |
|
1650
|
1666
|
= True
|
|
1651
|
1667
|
| otherwise
|
|
1652
|
1668
|
= case idDetails fn of
|
|
1653
|
|
- DataConWorkId {} -> True
|
|
|
1669
|
+ DataConWorkId {} -> True -- Even if the data constructor is strict
|
|
|
1670
|
+ -- See (WF1) in Note [exprIsWorkFree]
|
|
1654
|
1671
|
PrimOpId op _ -> primOpIsWorkFree op
|
|
1655
|
1672
|
_ -> False
|
|
1656
|
1673
|
|
| ... |
... |
@@ -1751,6 +1768,8 @@ expansion. Specifically: |
|
1751
|
1768
|
duplicate the (a +# b) primop, which we should not do lightly.
|
|
1752
|
1769
|
(It's quite hard to trigger this bug, but T13155 does so for GHC 8.0.)
|
|
1753
|
1770
|
|
|
|
1771
|
+NB: exprIsWorkFree implies exprIsExpandable.
|
|
|
1772
|
+
|
|
1754
|
1773
|
Note [isExpandableApp: bottoming functions]
|
|
1755
|
1774
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1756
|
1775
|
It's important that isExpandableApp does not respond True to bottoming
|