| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
| |
|
|
|
|
|
| |
because this is a convenience function for API users, calculate the
in-scope set from `exprFreeVars`.
|
|
|
|
|
|
|
| |
No need to mark the binders with markNonTailCalled, as they already have been
marked as such in rhs_udss' via adjust.
Differential Revision: https://phabricator.haskell.org/D3810
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
I discovered that in
let x = MkT y in ....(MKT y |> co)....
we weren't CSE'ing the (MkT y). The fix is easy.
|
| |
|
| |
|
| |
|
|
|
|
| |
This patch fixes the buglet described in Trac #13890.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
While investigating #12545, I discovered several places in the code
that performed length-checks like so:
```
length ts == 4
```
This is not ideal, since the length of `ts` could be much longer than 4,
and we'd be doing way more work than necessary! There are already a slew
of helper functions in `Util` such as `lengthIs` that are designed to do
this efficiently, so I found every place where they ought to be used and
did just that. I also defined a couple more utility functions for list
length that were common patterns (e.g., `ltLength`).
Test Plan: ./validate
Reviewers: austin, hvr, goldfire, bgamari, simonmar
Reviewed By: bgamari, simonmar
Subscribers: goldfire, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3622
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Simplifier tick exhaustion is not necessarily "impossible", and
isn't even always a GHC bug, per se. Improve the error message.
Furthermore, the simplifier code has access to `IO`, so we can
throw a proper `IO` exception instead of panicking.
Reviewers: austin, bgamari, angerman
Reviewed By: angerman
Subscribers: angerman, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3597
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Core allows non-recursive type-lets, thus
let a = TYPE ty in ...
They are substituted away very quickly, but it's convenient for
some passes to produce them (rather than to have to substitute
immediately).
Trac #13708 tried the effect of not running the simplifer at all
(a rather bizarre thing to do, but still). That showed that some
passes crashed because they always treated a let-bounder binder
as an Id. This patch adds some easy fixes.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The float-out pass uses a heuristic based on strictness info.
But it was getting the strictness info mis-aligned; I'd forgotten
that strictness flags only apply to /value/ arguments.
This patch fixes it. It has some surprising effects!
--------------------------------------------------------------------------------
Program Size Allocs Runtime Elapsed TotalMem
--------------------------------------------------------------------------------
integer -0.1% +9.9% +0.2% +0.2% +0.0%
lcss +0.0% +0.0% -11.9% -11.9% +0.0%
queens -0.2% +29.0% 0.02 0.02 +0.0%
simple -0.1% -22.6% -21.7% -21.7% -3.6%
treejoin +0.0% +0.0% -12.3% -12.6% +0.0%
--------------------------------------------------------------------------------
Min -0.2% -22.6% -21.7% -21.7% -10.0%
Max +3.3% +29.0% +19.2% +19.2% +50.0%
Geometric Mean +0.0% +0.1% -2.1% -2.1% +0.2%
The 'queens' and 'integer' allocation regressions are because, just
before let-floatting, we get
\v -> foldr k z (case x of I# y -> build ..y..)
Becase of Note [Case MFEs] we don't float the build; so fusion
happens. This increases allocation in queens because the build
isn't shared; but actaully runtime improves solidly. Situation
is similar in integer, although I think runtime gets a bit worse.
The bug meant that, because of foldr's type arguments, the
mis-aligned strictness info meant that the entire (case x ...)
was floated, so fusion failed, but sharing happened.
This is all very artificial-benchmark-ish so I'm not losing sleep
over it.
I did see some runtime numbers increasd, but I think it's noise;
the differnce went away when I tried them one by one afterwards.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit has a raft of refactorings that improve the treatment
of join points. I wasn't aiming so much as to gain performance as
to make the code simpler.
The two big things are these:
* Make mkDupableCont work for SimplBind as well. This is simpler than
I thought and quite neat. (Luke had aready done StrictArg.) That's
a win in its own right. But also now /all/ continuations can be made
dup-able
* Now that all continuations can be made dup-able, I could simplify
mkDupableCont to return just one SimplCont, instead of two.
That really is a worthwhile simlification! Much easier to think
about.
Plus a bunch of smaller things:
* Remove the join-arity that had been added to seIdSubst.
It can be done more simply by putting it in DoneEx, which
is the only constructor that actually needs it, and now we
don't need the unsavoury isJoinIdInEnv_maybe.
* Re-order the handling of join points in Simplify, so that we don't need
the horrible resultTypeOfDupableCont
* Add field names for StrictBind, StrictArg; and use them
* Define simplMonad.newJoinId, and use it
* Rename the seFloats field of SimplEnv to seLetFloats
Binary sizes seem to go up slightly, but allocations generally
improve, sometimes significantly. I don't believe the runtime numbers
are reliable enough to draw any conclusions about
--------------------------------------------------------------------------------
Program Size Allocs Runtime Elapsed TotalMem
--------------------------------------------------------------------------------
event +1.1% -12.0% -0.2% -0.2% -8.7%
fulsom +1.9% -11.8% -10.0% -10.0% +5.3%
last-piece +2.3% -1.2% -1.2% -1.2% +0.0%
mate +0.9% -1.4% -0.6% -0.7% +0.0%
multiplier +1.5% -8.3% 0.17 0.17 +0.0%
parser +2.0% +1.0% 0.04 0.04 +0.0%
parstof +1.5% +0.7% 0.01 0.01 +0.0%
sched +1.3% -6.1% 0.03 0.03 +0.0%
simple +1.8% +1.0% +9.7% +9.6% +0.0%
--------------------------------------------------------------------------------
Min +0.5% -12.0% -10.0% -10.0% -8.7%
Max +3.0% +1.0% +14.2% +14.2% +50.0%
Geometric Mean +1.4% -0.4% +0.3% +0.4% +0.5%
There's also a tests/perf/compiler improvement of 20% allocation in
T6048. I think it's because we now generate smaller code.
|
|
|
|
| |
Our new CPP linter enforces this.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
See Note [Scrutinee Constant Folding] in SimplUtils
* Add cases for tagToEnum and dataToTag. This is the main new
bit. It allows the simplifier to remove the pervasive uses
of case tagToEnum (a > b) of
False -> e1
True -> e2
and replace it by the simpler
case a > b of
DEFAULT -> e1
1# -> e2
See Note [caseRules for tagToEnum]
and Note [caseRules for dataToTag] in PrelRules.
* This required some changes to the API of caseRules, and hence
to code in SimplUtils. See Note [Scrutinee Constant Folding]
in SimplUtils.
* Avoid duplication of work in the (unusual) case of
case BIG + 3# of b
DEFAULT -> e1
6# -> e2
Previously we got
case BIG of
DEFAULT -> let b = BIG + 3# in e1
3# -> let b = 6# in e2
Now we get
case BIG of b#
DEFAULT -> let b = b' + 3# in e1
3# -> let b = 6# in e2
* Avoid duplicated code in caseRules
A knock-on refactoring:
* Move Note [Word/Int underflow/overflow] to Literal, as
documentation to accompany mkMachIntWrap etc; and get
rid of PrelRuls.intResult' in favour of mkMachIntWrap
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
extendCSRecEnv took the map to be extended from cs_map instead of
cs_rec_map. Oops!
Test Plan: Validate
Reviewers: simonpj, austin
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3510
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If we see f (g x), and f is strict, we want to be a bit more eager to
inline g, because it may well expose an eval (on x perhaps) that can
be eliminated or shared.
I saw this in nofib boyer2, function RewriteFuns.onewayunify1. It
showed up as a consequence of the preceding patch that makes the
simplifier do less work (Trac #13379). We had
f d (g x)
where f was a class-op. Previously we simplified both d and
(g x) with a RuleArgCtxt (making g a bit more eager to inline).
But now we simplify only d that way, then fire the rule, and
only then simplify (g x). Firing the rule produces a strict
funciion, so we want to make a strict function encourage
inlining a bit.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This patch nails a Bad Bug exposed in Trac #13379. Roughly,
a deeply-nested application like
f (f (f ....) ) )
could make the simplifier go exponential -- without producing
an exponential-sized result!
The reason was that we
- simplified a (big) function argument
- then decided to inline the function
- then preInilneUnconditionally the argument
- and then re-simplified the big argument
And if the "big argument" itself had a similar structure
things could get very bad.
Once I'd understood, it was easy to fix:
* See Note Note [Avoiding exponential behaviour] for an overview
* The key change is that Simplify.simplLam now as a case for
(isSimplified dup). This is what removes the perf bug.
* But I also made simplCast more parsimonious about simplifying,
avoiding doing so when the coercion is Refl
* And similarly I now try to avoid simplifying arguments
where possible before applying rules.
See Note [Trying rewrite rules]
The latter two points tackle common cases, and in those cases make the
simplifier take fewer iterations.
|
|
|
|
|
|
|
| |
We were failing to float a nested binding
x :: Addr# = "foo"#
to top level, even though we /were/ floating string
literals themselves. A small oversight, easily fixed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When doing type-in-type, Richard introduce some substantial
complications in CoreFVs, gathering types and free variables
of type. In Trac #13160 we decided that this complication was
unnecessary, so this patch removes it.
Unfortnately I then fell down a twisty rabbit hole. Roughly:
* An apparently-innocuous change in the AnnApp case of
fiExpr made the fuction a little bit stricter, so we ended
up peering into the arguments when we didn't before (namely
when there are no bindings being floated inwards). I've
rejigged it so that it's not fragile any more.
* Peering into the arguments was sometimes expensive, becuase
exprIsExpandable can be expensive because it looks deeply into
the expression.
* The combination of the two led to a non-linear explosion
of work when the argument of a function is a deeep nest
of constructors. This bug has been lurking for ages.
I solved it by replacing exprIsExpandable with exprIsHNF
+ exprIsTrivial; see Note [noFloatInto considerations]
* The code around floating case-expressions turned out to be
very delicate, because can_fail primops (which we want to
float inwards) can't be floated outwards; so we have to be
careful never to float them too far. Note [Floating primops]
has the details
* I ended up refactoring some rather opaque code in
sepBindsByDropPoint.
Working all this out meant that I rewrote quite a bit of
code, so it's now a reasonably substantial patch. But it's
a net improvement.
|
| |
|
|
|
|
| |
as discussed in #13479.
|
|
|
|
|
|
|
|
|
|
| |
This patch fixes Trac #13468, and at the same time makes the
code simpler and more uniform. In particular, I've eliminated
the awkward conflict between the old built-in rule for seq
(which elimianted a cast), and the desire to make case scrutinse
a data type by doing type-family reduction (which adds a cast).
Nice.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Part of e13419c55 was accidentally lost during a rebase. This commit
adds the missing change, along with some more improvements
regarding where we do and don't use `seqType`.
Also include a comment about where the space leak showed up
and a Note explaining the strategy being used here.
Test Plan: harbormaster, plus local testing on DynFlags
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D3421
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This refactoring makes it more obvious when we are constructing
a Node for the digraph rather than a less useful 3-tuple.
Reviewers: austin, goldfire, bgamari, simonmar, dfeuer
Reviewed By: dfeuer
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3414
|
|
|
|
| |
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
It was expensive, as the simplifier runs for many iterations,
and probably not very useful.
Test Plan: harbormaster
Reviewers: austin, bgamari, dfeuer
Reviewed By: dfeuer
Subscribers: dfeuer, thomie
Differential Revision: https://phabricator.haskell.org/D3391
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The Join points commit (8d5cf8bf) introduced a space leak
somewhere in the simplifier. The extra strictness added in this commit
fixes the leak. Unfortunately I don't really understand the details.
Unfortunately, the extra strictness appears to result in more overall
allocations in some cases, even while the peak heap size decreases in others.
Test Plan: harbormaster
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D3399
|
|
|
|
|
|
|
|
|
| |
This small refactoring, provoked by comment:18 on Trac #13426,
makes it so that simplExprF never gets a (Type ty) expression to
simplify, which in turn means that calls to exprType on its argument
will always succeed.
No change in behaviour.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
It is sometimes hard to find where a rule is defined. Printing the
module where it comes from will make it much easier to find.
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3378
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
As #13479 shows, there are corner cases where the simplifier decides to
not eta-expand a function as much as its call arity would suggest, but
instead transforms the code that the call arity annotation becomes a
lie.
As the call arity information is only meant to be used by the
immediatelly following simplifier run, it makes sense to simply zap the
information there.
Differential Revision: https://phabricator.haskell.org/D3390
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The commit 6746549772c5cc0ac66c0fce562f297f4d4b80a2
Author: Richard Eisenberg <eir@cis.upenn.edu>
Date: Fri Dec 11 18:19:53 2015 -0500
Add kind equalities to GHC.
added this entirely bogus code to Simplify.simplLam:
env' | Coercion co <- arg
= extendCvSubst env bndr co
| otherwise
= env
It's bogus because 'co' is an 'InCoercion', but a CvSubst should have
only OutCoercions in it. Moreover, completeBind does the job nicely.
This led to an ASSERT failure in an experimental branch; but I have
not got a repro case that works on HEAD. But still, the patch deletes
code and fixes a bug, so it must be good.
The only mystery is why Richard added it in the first place :-).
I hope I'm not missing anything. But it validates fine.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
One commented out tracing function didn't type check and also show the
scores of loop breaker nodes.
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3371
|
| |
|
|
|
|
|
|
|
|
|
|
| |
Reviewers: austin, bgamari, dfeuer
Reviewed By: bgamari, dfeuer
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3360
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The main payload of this patch is NOT to make a join-point
from a function with an INLINE pragma and the wrong arity;
see Note [Join points and INLINE pragmas] in CoreOpt.
This is what caused Trac #13413.
But we must do the exact same thing in simpleOptExpr,
which drove me to the following refactoring:
* Move simpleOptExpr and simpleOptPgm from CoreSubst to a new
module CoreOpt along with a few others (exprIsConApp_maybe,
pushCoArg, etc)
This eliminates a module loop altogether (delete
CoreArity.hs-boot), and stops CoreSubst getting too huge.
* Rename Simplify.matchOrConvertToJoinPoint
to joinPointBinding_maybe
Move it to the new CoreOpt
Use it in simpleOptExpr as well as in Simplify
* Define CoreArity.joinRhsArity and use it
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This factors out the repetition of (log_action dflags dflags) and will
hopefully allow us to someday better abstract log output.
Test Plan: Validate
Reviewers: austin, hvr, goldfire
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3334
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In this commit
commit 02ac2974ce8e537372bff8d9e0a6efb461ed2c59
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date: Wed Nov 16 10:37:47 2011 +0000
Fix CaseIdentity optimisaion
In fixing one bug I'd introduced another;
case x of { T -> T; F -> F }
wasn't getting optmised! Trivial to fix.
I introduced yet another! This line of code in SimplUtils.mkCase1
check_eq (Var v) (DataAlt con) [] = v == dataConWorkId con
-- Optimisation only
is patently false when arg_tys is non-empty. Astonishing that it
has not shown up before now.
Easily fixed though. This was all shown up by Trac #13417, which is
now fixed.
Merge to 8.0, 8.2.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
Test Plan: No new test (bug is latent)
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3285
|
|
|
|
|
|
|
|
|
|
| |
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3320
|
| |
|
| |
|
| |
|