[Git][ghc/ghc][master] 2 commits: Add -fno-cse to T15426 and T18964
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Wed Sep 13 12:08:00 UTC 2023
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
98e7c1cf by Simon Peyton Jones at 2023-09-13T08:06:40-04:00
Add -fno-cse to T15426 and T18964
This -fno-cse change is to avoid these performance tests depending on
flukey CSE stuff. Each contains several independent tests, and we don't
want them to interact.
See #23925.
By killing CSE we expect a 400% increase in T15426, and 100% in T18964.
Metric Increase:
T15426
T18964
- - - - -
236a134e by Simon Peyton Jones at 2023-09-13T08:06:40-04:00
Tiny refactor
canEtaReduceToArity was only called internally, and always with
two arguments equal to zero. This patch just specialises the
function, and renames it to cantEtaReduceFun.
No change in behaviour.
- - - - -
3 changed files:
- compiler/GHC/Core/Opt/Arity.hs
- testsuite/tests/perf/should_run/T15426.hs
- testsuite/tests/perf/should_run/T18964.hs
Changes:
=====================================
compiler/GHC/Core/Opt/Arity.hs
=====================================
@@ -87,6 +87,8 @@ import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Utils.Misc
+import Data.Maybe( isJust )
+
{-
************************************************************************
* *
@@ -2376,7 +2378,7 @@ perform eta reduction on an expression with n leading lambdas `\xs. e xs`
(checked in 'is_eta_reduction_sound' in 'tryEtaReduce', which focuses on the
case where `e` is trivial):
- A. It is sound to eta-reduce n arguments as long as n does not exceed the
+(A) It is sound to eta-reduce n arguments as long as n does not exceed the
`exprArity` of `e`. (Needs Arity analysis.)
This criterion exploits information about how `e` is *defined*.
@@ -2385,7 +2387,7 @@ case where `e` is trivial):
By contrast, it would be *unsound* to eta-reduce 2 args, `\x y. e x y` to `e`:
`e 42` diverges when `(\x y. e x y) 42` does not.
- S. It is sound to eta-reduce n arguments in an evaluation context in which all
+(S) It is sound to eta-reduce n arguments in an evaluation context in which all
calls happen with at least n arguments. (Needs Strictness analysis.)
NB: This treats evaluations like a call with 0 args.
NB: This criterion exploits information about how `e` is *used*.
@@ -2412,13 +2414,13 @@ case where `e` is trivial):
See Note [Eta reduction based on evaluation context] for the implementation
details. This criterion is tested extensively in T21261.
- R. Note [Eta reduction in recursive RHSs] tells us that we should not
+(R) Note [Eta reduction in recursive RHSs] tells us that we should not
eta-reduce `f` in its own RHS and describes our fix.
There we have `f = \x. f x` and we should not eta-reduce to `f=f`. Which
might change a terminating program (think @f `seq` e@) to a non-terminating
one.
- E. (See fun_arity in tryEtaReduce.) As a perhaps special case on the
+(E) (See fun_arity in tryEtaReduce.) As a perhaps special case on the
boundary of (A) and (S), when we know that a fun binder `f` is in
WHNF, we simply assume it has arity 1 and apply (A). Example:
g f = f `seq` \x. f x
@@ -2428,7 +2430,7 @@ case where `e` is trivial):
And here are a few more technical criteria for when it is *not* sound to
eta-reduce that are specific to Core and GHC:
- L. With linear types, eta-reduction can break type-checking:
+(L) With linear types, eta-reduction can break type-checking:
f :: A ⊸ B
g :: A -> B
g = \x. f x
@@ -2436,13 +2438,13 @@ eta-reduce that are specific to Core and GHC:
complain that g and f don't have the same type. NB: Not unsound in the
dynamic semantics, but unsound according to the static semantics of Core.
- J. We may not undersaturate join points.
+(J) We may not undersaturate join points.
See Note [Invariants on join points] in GHC.Core, and #20599.
- B. We may not undersaturate functions with no binding.
+(B) We may not undersaturate functions with no binding.
See Note [Eta expanding primops].
- W. We may not undersaturate StrictWorkerIds.
+(W) We may not undersaturate StrictWorkerIds.
See Note [CBV Function Ids] in GHC.Types.Id.Info.
Here is a list of historic accidents surrounding unsound eta-reduction:
@@ -2699,7 +2701,7 @@ tryEtaReduce rec_ids bndrs body eval_sd
|| all_calls_with_arity incoming_arity) -- criterion (S)
-- ... and that the function can be eta reduced to arity 0
-- without violating invariants of Core and GHC
- && canEtaReduceToArity fun 0 0 -- criteria (L), (J), (W), (B)
+ && not (cantEtaReduceFun fun) -- criteria (L), (J), (W), (B)
all_calls_with_arity n = isStrict (fst $ peelManyCalls n eval_sd)
-- See Note [Eta reduction based on evaluation context]
@@ -2754,19 +2756,18 @@ tryEtaReduce rec_ids bndrs body eval_sd
ok_arg _ _ _ _ = Nothing
--- | Can we eta-reduce the given function to the specified arity?
+-- | Can we eta-reduce the given function
-- See Note [Eta reduction soundness], criteria (B), (J), (W) and (L).
-canEtaReduceToArity :: Id -> JoinArity -> Arity -> Bool
-canEtaReduceToArity fun dest_join_arity dest_arity =
- not $
- hasNoBinding fun -- (B)
+cantEtaReduceFun :: Id -> Bool
+cantEtaReduceFun fun
+ = hasNoBinding fun -- (B)
-- Don't undersaturate functions with no binding.
- || ( isJoinId fun && dest_join_arity < idJoinArity fun ) -- (J)
+ || isJoinId fun -- (J)
-- Don't undersaturate join points.
-- See Note [Invariants on join points] in GHC.Core, and #20599
- || ( dest_arity < idCbvMarkArity fun ) -- (W)
+ || (isJust (idCbvMarks_maybe fun)) -- (W)
-- Don't undersaturate StrictWorkerIds.
-- See Note [CBV Function Ids] in GHC.Types.Id.Info.
=====================================
testsuite/tests/perf/should_run/T15426.hs
=====================================
@@ -1,3 +1,8 @@
+{-# OPTIONS_GHC -fno-cse #-}
+ -- Avoid depending on flukey CSE; there are really 5 independent
+ -- tests in this module, and we don't want them to interact.
+ -- See #23925
+
import Control.Exception (evaluate)
import qualified Data.List as L
@@ -28,4 +33,4 @@ As a result these lists are now floated out and shared.
Just leaving breadcrumbs, in case we later see big perf changes on
this (slightly fragile) benchmark.
--}
\ No newline at end of file
+-}
=====================================
testsuite/tests/perf/should_run/T18964.hs
=====================================
@@ -1,3 +1,8 @@
+{-# OPTIONS_GHC -fno-cse #-}
+ -- Avoid depending on flukey CSE; there are really 4 independent
+ -- tests in this module, and we don't want them to interact.
+ -- See #23925
+
import GHC.Exts
import Data.Int
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9217950baf0665c9ec71bdd5aa59710de6d8b31d...236a134eab4c0a3aae30752a3d580c083f4e6b57
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9217950baf0665c9ec71bdd5aa59710de6d8b31d...236a134eab4c0a3aae30752a3d580c083f4e6b57
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230913/b7f686ba/attachment-0001.html>
More information about the ghc-commits
mailing list