1. 17 Mar, 2017 1 commit
    • Simon Peyton Jones's avatar
      No join-point from an INLINE function with wrong arity · a7dbafe9
      Simon Peyton Jones authored
      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
      a7dbafe9
  2. 14 Mar, 2017 1 commit
    • Simon Peyton Jones's avatar
      Fix CaseIdentity optimisation AGAIN · 82b40598
      Simon Peyton Jones authored
      In this commit
          commit 02ac2974
          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.
      82b40598
  3. 06 Mar, 2017 1 commit
  4. 02 Mar, 2017 1 commit
  5. 28 Feb, 2017 2 commits
    • Simon Peyton Jones's avatar
      The Early Inline Patch · 2effe18a
      Simon Peyton Jones authored
      This very small patch switches on sm_inline even in the InitialPhase
      (aka "gentle" phase).   There is no reason not to... and the results
      are astonishing.
      
      I think the peformance of GHC itself improves by about 5%; and some
      programs get much smaller, quicker.  Result: across the board
      irmprovements in
      compile time performance.  Here are the changes in perf/compiler;
      the numbers are decreases in compiler bytes-allocated:
      
        3%   T5837
        7%   parsing001
        9%   T12234
        35%  T9020
        9%   T3064
        13%  T9961
        20%  T13056
        5%   T9872d
        5%   T9872c
        5%   T9872b
        7%   T9872a
        5%   T783
        35%  T12227
        20%  T1969
      
      Plus in perf/should_run
      
        5%   lazy-bs-alloc
      
      It wasn't as easy as it sounds: I did a raft of preparatory work in
      earlier patches.  But it's great!
      
      Reviewers: austin, bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3203
      2effe18a
    • rwbarton's avatar
      When floating, don't box an expression that's okay for speculation (#13338) · d0508ef0
      rwbarton authored
      Commit 432f952e (Float unboxed expressions by boxing) lets the float-out pass
      turn, for example,
      
          ... (-# (remInt# x# 100000#) i#) ...
      
      into
      
          let lvl :: Int
              lvl = case remInt# x# 100000# of v { __DEFAULT__ -> I# v }
          in ... (-# (case lvl of { I# v -> v }) i#) ...
      
      But when, as in the example above, the expression that was floated out was
      the argument of an application, the resulting application may no longer
      satisfy the let/app invariant, because exprOkForSpeculation doesn't look
      far enough inside the definition of lvl.
      
      Solution: When the expression we floated out was okay for speculation, don't
      bother boxing it. It will be evaluated earlier, and that's okay by assumption.
      Fixes the let/app invariant and is cheaper too.
      
      Test Plan: make slowtest TEST=T13338
      
      Reviewers: austin, bgamari, simonpj
      
      Reviewed By: bgamari, simonpj
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3217
      d0508ef0
  6. 26 Feb, 2017 2 commits
    • rwbarton's avatar
      tests: remove extra_files.py (#12223) · 3415bcaa
      rwbarton authored
      The script I used is included as testsuite/driver/kill_extra_files.py,
      though at this point it is for mostly historical interest.
      
      Some of the tests in libraries/hpc relied on extra_files.py, so this
      commit includes an update to that submodule.
      
      One test in libraries/process also relies on extra_files.py, but we
      cannot update that submodule so easily, so for now we special-case it
      in the test driver.
      3415bcaa
    • Ben Gamari's avatar
      Add testcase for #13340 · 517ad201
      Ben Gamari authored
      Test Plan: Validate
      
      Reviewers: rwbarton, austin
      
      Reviewed By: rwbarton
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3215
      517ad201
  7. 24 Feb, 2017 1 commit
    • Simon Peyton Jones's avatar
      Make exprIsConApp_maybe work better for literals strings · a6e13d50
      Simon Peyton Jones authored
      There are two things here
      
      * Use exprIsLiteral_maybe to "look through" a variable bound
        to a literal string.
      
      * Add CONLIKE to the NOINLINE pragma for unpackCString# and
        unpackCStringUtf8#
      
      See Trac #13317, Trac #10844, and
      Note [exprIsConApp_maybe on literal strings] in CoreSubst
      
      I did a nofib run and got essentially zero change except for one
      2.2% improvement in allocation for 'pretty'.
      a6e13d50
  8. 06 Feb, 2017 1 commit
    • Eric Seidel's avatar
      Do Worker/Wrapper for NOINLINE things · b572aadb
      Eric Seidel authored
      Disabling worker/wrapper for NOINLINE things can cause unnecessary
      reboxing of values. Consider
      
          {-# NOINLINE f #-}
          f :: Int -> a
          f x = error (show x)
      
          g :: Bool -> Bool -> Int -> Int
          g True  True  p = f p
          g False True  p = p + 1
          g b     False p = g b True p
      
      the strictness analysis will discover f and g are strict, but because f
      has no wrapper, the worker for g will rebox p. So we get
      
          $wg x y p# =
            let p = I# p# in  -- Yikes! Reboxing!
            case x of
              False ->
                case y of
                  False -> $wg False True p#
                  True -> +# p# 1#
              True ->
                case y of
                  False -> $wg True True p#
                  True -> case f p of { }
      
          g x y p = case p of (I# p#) -> $wg x y p#
      
      Now, in this case the reboxing will float into the True branch, an so
      the allocation will only happen on the error path. But it won't float
      inwards if there are multiple branches that call (f p), so the reboxing
      will happen on every call of g. Disaster.
      
      Solution: do worker/wrapper even on NOINLINE things; but move the
      NOINLINE pragma to the worker.
      
      Test Plan: make test TEST="13143"
      
      Reviewers: simonpj, bgamari, dfeuer, austin
      
      Reviewed By: simonpj, bgamari
      
      Subscribers: dfeuer, thomie
      
      Differential Revision: https://phabricator.haskell.org/D3046
      b572aadb
  9. 01 Feb, 2017 1 commit
  10. 24 Jan, 2017 1 commit
    • rwbarton's avatar
      Re-sort case alternatives after scrutinee constant folding (#13170) · abaa6815
      rwbarton authored
      Commit d3b546b1 added a "scrutinee constant folding" pass
      that rewrites a case expression whose scrutinee is an expression like
      x +# 3#. But case expressions are supposed to have their alternatives in
      sorted order, so when the scrutinee is (for example) negateInt# x#, we
      need to re-sort the alternatives after mapping their values.
      
      This showed up as a core lint failure when compiling System.Process.Posix:
      
          isSigIntQuit n = sig == sigINT || sig == sigQUIT
              where sig = fromIntegral (-n)
      
      Data.List.sortBy is supposed to be linear-time on sorted or reverse-sorted
      input, so it is probably not worth doing anything more clever than this.
      
      Test Plan: Added a new test T13170 for the above case.
      
      Reviewers: austin, hsyl20, simonpj, bgamari
      
      Reviewed By: hsyl20, simonpj, bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D3008
      
      GHC Trac Issues: #13170
      abaa6815
  11. 22 Jan, 2017 1 commit
  12. 20 Jan, 2017 4 commits
    • takano-akio's avatar
      Allow top-level string literals in Core (#8472) · d49b2bb2
      takano-akio authored
      This commits relaxes the invariants of the Core syntax so that a
      top-level variable can be bound to a primitive string literal of type
      Addr#.
      
      This commit:
      
      * Relaxes the invatiants of the Core, and allows top-level bindings whose
        type is Addr# as long as their RHS is either a primitive string literal or
        another variable.
      
      * Allows the simplifier and the full-laziness transformer to float out
        primitive string literals to the top leve.
      
      * Introduces the new StgGenTopBinding type to accomodate top-level Addr#
        bindings.
      
      * Introduces a new type of labels in the object code, with the suffix "_bytes",
        for exported top-level Addr# bindings.
      
      * Makes some built-in rules more robust. This was necessary to keep them
        functional after the above changes.
      
      This is a continuation of D2554.
      
      Rebasing notes:
      This had two slightly suspicious performance regressions:
      
      * T12425: bytes allocated regressed by roughly 5%
      * T4029: bytes allocated regressed by a bit over 1%
      * T13035: bytes allocated regressed by a bit over 5%
      
      These deserve additional investigation.
      
      Rebased by: bgamari.
      
      Test Plan: ./validate --slow
      
      Reviewers: goldfire, trofi, simonmar, simonpj, austin, hvr, bgamari
      
      Reviewed By: trofi, simonpj, bgamari
      
      Subscribers: trofi, simonpj, gridaphobe, thomie
      
      Differential Revision: https://phabricator.haskell.org/D2605
      
      GHC Trac Issues: #8472
      d49b2bb2
    • Simon Peyton Jones's avatar
      Test Trac #11444 · b8f1b018
      Simon Peyton Jones authored
      b8f1b018
    • Simon Peyton Jones's avatar
      Simplify and improve CSE · b78fa759
      Simon Peyton Jones authored
      Trac #13156 showed a lost opportunity for CSE. I found that it was
      easy to fix, and it had the nice side effect of rendering a previous
      nasty case, described in Note [Corner case for case expressions],
      unnecessary.
      
      Simpler code, does more.  Great.
      b78fa759
    • Simon Peyton Jones's avatar
      Fix a nasty bug in exprIsExpandable · 9be18ea4
      Simon Peyton Jones authored
      This bug has been lurking for ages: Trac #13155
      
      The important semantic change is to ensure that exprIsExpandable
      returns False for primop calls.  Previously exprIsExpandable used
      exprIsCheap' which always used primOpIsCheap.
      
      I took the opportunity to combine the code for exprIsCheap' (two
      variants: exprIsCheap and exprIsExpandable) with that for
      exprIsWorkFree.  Result is simpler, tighter, easier to understand.
      And correct (at least wrt this bug)!
      9be18ea4
  13. 23 Dec, 2016 4 commits
    • Sylvain Henry's avatar
      Fix test for T12877 · 1b06231e
      Sylvain Henry authored
      Summary: See https://phabricator.haskell.org/rGHCd3b546b1a605
      
      Reviewers: nomeata, austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D2883
      1b06231e
    • Simon Peyton Jones's avatar
      Push coercions in exprIsConApp_maybe · b4c3a668
      Simon Peyton Jones authored
      Trac #13025 showed up the fact that exprIsConApp_maybe isn't
      clever enough: it didn't push coercions through applicatins, and that
      meant we weren't getting as much superclass selection as we should.
      
      It's easy to fix, happily.
      
      See Note [Push coercions in exprIsConApp_maybe]
      b4c3a668
    • Simon Peyton Jones's avatar
      Propagate evaluated-ness a bit more faithfully · 75e8c305
      Simon Peyton Jones authored
      This was provoked by Trac #13027.
      
      The fix in Simplify actually cures the reported bug; see
      Note [Case binder evaluated-ness] in Simplify.
      
      The fix in CoreTidy looks like an omission that I fixed while I
      was at it.
      75e8c305
    • Simon Peyton Jones's avatar
      Float unboxed expressions by boxing · 432f952e
      Simon Peyton Jones authored
      This patch makes GHC's floating more robust, by allowing it
      to float unboxed expressions of at least some common types.
      
      See Note [Floating MFEs of unlifted type] in SetLevels.
      
      This was all provoked by Trac #12603
      
      In working this through I also made a number of other corner-case
      changes in SetLevels:
      
      * Previously we inconsistently use exprIsBottom (which checks for
        bottom) instead of exprBotStrictness_maybe (which checks for
        bottoming functions).  As well as being inconsistent it was
        simply less good.
      
        See Note [Bottoming floats]
      
      * I fixed a case where were were unprofitably floating an
        expression because we thought it escaped a value lambda
        (see Note [Escaping a value lambda]).  The relevant code is
             float_me = (dest_lvl `ltMajLvl` (le_ctxt_lvl env)
                        && not float_is_lam)   -- NEW
      
      * I made lvlFloatRhs work properly in the case where abs_vars
        is non-empty.  It wasn't wrong before, but it did some stupid
        extra floating.
      432f952e
  14. 21 Dec, 2016 1 commit
  15. 13 Dec, 2016 1 commit
  16. 12 Dec, 2016 1 commit
    • Simon Peyton Jones's avatar
      Float unboxed expressions by boxing · bc3d37da
      Simon Peyton Jones authored
      This patch makes GHC's floating more robust, by allowing it
      to float unboxed expressions of at least some common types.
      
      See Note [Floating MFEs of unlifted type] in SetLevels.
      
      This was all provoked by Trac #12603
      bc3d37da
  17. 28 Nov, 2016 1 commit
  18. 05 Sep, 2016 1 commit
  19. 30 Aug, 2016 1 commit
  20. 21 Aug, 2016 2 commits
  21. 21 Jun, 2016 1 commit
  22. 09 Jun, 2016 1 commit
  23. 18 May, 2016 1 commit
  24. 17 May, 2016 1 commit
    • thomie's avatar
      Testsuite: run tests in /tmp after copying required files · 3f3dc23e
      thomie authored
      Major change to the testsuite driver.
      
      For each TEST:
         * create a directory `<testdir>` inside `/tmp`.
      
         * link/copy all source files that the test needs into `<testdir>`.
      
         * run the test inside `<testdir>`.
      
         * delete `<testdir>`
      
      Extra files are (temporarily) tracked in
      `testsuite/driver/extra_files.py`, but can also be specified using the
      `extra_files` setup function.
      
      Differential Revision: https://phabricator.haskell.org/D1187
      
      Reviewed by: Rufflewind, bgamari
      
      Trac: #11980
      3f3dc23e
  25. 22 Apr, 2016 1 commit
  26. 24 Mar, 2016 1 commit
    • Simon Peyton Jones's avatar
      Tidy up handling of coercion variables · cb08f8da
      Simon Peyton Jones authored
      * Comments to explain that a CoVar, whose IdInfo is CoVarId,
        is always unlifted (but may be nominal or representational role)
      
        And TyCoRep.isCoercionType picks out only those unlifted
        types, NOT the lifted versions
      
      * Introduce Var.NcId for non-co-var Ids
        with predicate isNonCoVarId
      
      * Add assertions in CoreSubst that the Id env is only
        used for NcIds
      
      * Fix lurking bug in CSE which extended the
        CoreSubst Id env with a CoVar
      
      * Fix two bugs in Specialise.spec_call, which wrongly treated
        CoVars like NcIds
          - needed a varToCoreExpr in one place
          - needed extendSubst not extendIdSubst in another
        This was the root cause of Trac #11644
      
      Minor refactoring
      
      * Eliminate unused mkDerivedLocalCoVarM, mkUserLocalCoVar
      * Small refactor in mkSysLocalOrCoVar
      cb08f8da
  27. 23 Mar, 2016 1 commit
  28. 25 Feb, 2016 2 commits
  29. 11 Feb, 2016 1 commit
    • Simon Peyton Jones's avatar
      Always do eta-reduction · 85008555
      Simon Peyton Jones authored
      See Note [Eta-reduction in -O0] in DynFlags.
      
      Bottom line: doing eta reduction unconditionally is benign, and
      removes an ASSERT failure (Trac #11562).
      85008555
  30. 17 Dec, 2015 1 commit
    • eir@cis.upenn.edu's avatar
      Fix #11232. · cab13162
      eir@cis.upenn.edu authored
      I somehow forgot to propagate roles into UnivCos. Very
      simple fix, happily.
      
      Test Plan: simplCore/should_compile/T11232
      
      Reviewers: bgamari, austin, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: simonpj, thomie
      
      Differential Revision: https://phabricator.haskell.org/D1645
      
      GHC Trac Issues: #11232
      cab13162