Better eta-expansion (again) and don't specilise DFuns
This patch fixes #18223, which made GHC generate an exponential amount of code. There are three quite separate changes in here 1. Re-engineer eta-expansion (again). The eta-expander was generating lots of intermediate stuff, which could be optimised away, but which choked the simplifier meanwhile. Relatively easy to kill it off at source. See Note [The EtaInfo mechanism] in GHC.Core.Opt.Arity. The main new thing is the use of pushCoArg in getArg_maybe. 2. Stop Specialise specalising DFuns. This is the cause of a huge (and utterly unnecessary) blowup in program size in #18223. See Note [Do not specialise DFuns] in GHC.Core.Opt.Specialise. I also refactored the Specialise monad a bit... it was silly, because it passed on unchanging values as if they were mutable state. 3. Do an extra Simplifer run, after SpecConstra and before late-Specialise. I found (investigating perf/compiler/T16473) that failing to do this was crippling *both* SpecConstr *and* Specialise. See Note [Simplify after SpecConstr] in GHC.Core.Opt.Pipeline. This change does mean an extra run of the Simplifier, but only with -O2, and I think that's acceptable. T16473 allocates *three* times less with this change. (I changed it to check runtime rather than compile time.) Some smaller consequences * I moved pushCoercion, pushCoArg and friends from SimpleOpt to Arity, because it was needed by the new etaInfoApp. And pushCoValArg now returns a MCoercion rather than Coercion for the argument Coercion. * A minor, incidental improvement to Core pretty-printing This does fix #18223, (which was otherwise uncompilable. Hooray. But there is still a big intermediate because there are some very deeply nested types in that program. Modest reductions in compile-time allocation on a couple of benchmarks T12425 -2.0% T13253 -10.3% Metric increase with -O2, due to extra simplifier run T9233 +5.8% T12227 +1.8% T15630 +5.0% There is a spurious apparent increase on heap residency on T9630, on some architectures at least. I tried it with -G1 and the residency is essentially unchanged. Metric Increase T9233 T12227 T9630 Metric Decrease T12425 T13253
Showing
- compiler/GHC/Core/Coercion.hs 41 additions, 26 deletionscompiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Opt/Arity.hs 476 additions, 69 deletionscompiler/GHC/Core/Opt/Arity.hs
- compiler/GHC/Core/Opt/Pipeline.hs 39 additions, 13 deletionscompiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify.hs 22 additions, 16 deletionscompiler/GHC/Core/Opt/Simplify.hs
- compiler/GHC/Core/Opt/Simplify/Env.hs 1 addition, 1 deletioncompiler/GHC/Core/Opt/Simplify/Env.hs
- compiler/GHC/Core/Opt/Specialise.hs 141 additions, 138 deletionscompiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Core/Ppr.hs 11 additions, 7 deletionscompiler/GHC/Core/Ppr.hs
- compiler/GHC/Core/SimpleOpt.hs 23 additions, 301 deletionscompiler/GHC/Core/SimpleOpt.hs
- compiler/GHC/Core/Subst.hs 5 additions, 0 deletionscompiler/GHC/Core/Subst.hs
- testsuite/tests/perf/compiler/Makefile 0 additions, 4 deletionstestsuite/tests/perf/compiler/Makefile
- testsuite/tests/perf/compiler/T16473.stdout 1 addition, 97 deletionstestsuite/tests/perf/compiler/T16473.stdout
- testsuite/tests/perf/compiler/T18223.hs 78 additions, 0 deletionstestsuite/tests/perf/compiler/T18223.hs
- testsuite/tests/perf/compiler/all.T 12 additions, 1 deletiontestsuite/tests/perf/compiler/all.T
- testsuite/tests/printer/T18052a.stderr 1 addition, 1 deletiontestsuite/tests/printer/T18052a.stderr
- testsuite/tests/simplCore/should_compile/T17966.stdout 0 additions, 3 deletionstestsuite/tests/simplCore/should_compile/T17966.stdout
- testsuite/tests/stranal/should_compile/T18122.stderr 19 additions, 21 deletionstestsuite/tests/stranal/should_compile/T18122.stderr
Loading
Please register or sign in to comment