summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simon.peytonjones@gmail.com>2022-01-28 10:26:40 +0000
committerSimon Peyton Jones <simon.peytonjones@gmail.com>2022-02-02 11:27:35 +0000
commit34d6268fff58be296389ecba721d1a9ab534a4b8 (patch)
treeafe788a51bf169aa61bfbb18fd1ac6e3d3172e66
parent88fba8a4b3c22e953a634b81dd0b67ec66eb5e72 (diff)
downloadhaskell-wip/T20941.tar.gz
Two small improvements in the Simplifierwip/T20941
As #20941 describes, this patch implements a couple of small fixes to the Simplifier. They make a difference principally with -O0, so few people will notice. But with -O0 they can reduce the number of Simplifer iterations. * In occurrence analysis we avoid making x = (a,b) into a loop breaker because we want to be able to inline x, or (more likely) do case-elimination. But HEAD does not treat x = let y = blah in (a,b) in the same way. We should though, because we are going to float that y=blah out of the x-binding. A one-line fix in OccurAnal. * The crucial function exprIsConApp_maybe uses getUnfoldingInRuleMatch (rightly) but the latter was deeply strange. In HEAD, if rule-rewriting was off (-O0) we only looked inside stable unfoldings. Very stupid. The patch simplifies. * I also noticed that in simplStableUnfolding we were failing to delete the DFun binders from the usage. So I added that. Practically zero perf change across the board, except that we get more compiler allocation in T3064 (which is compiled with -O0). There's a good reason: we get better code. But there are lots of other small compiler allocation decreases: Metrics: compile_time/bytes allocated --------------------- Baseline Test Metric value New value Change ----------------------------------------------------------------- PmSeriesG(normal) ghc/alloc 44,260,817 44,184,920 -0.2% PmSeriesS(normal) ghc/alloc 52,967,392 52,891,632 -0.1% PmSeriesT(normal) ghc/alloc 75,498,220 75,421,968 -0.1% PmSeriesV(normal) ghc/alloc 52,341,849 52,265,768 -0.1% T10421(normal) ghc/alloc 109,702,291 109,626,024 -0.1% T10421a(normal) ghc/alloc 76,888,308 76,809,896 -0.1% T10858(normal) ghc/alloc 125,149,038 125,073,648 -0.1% T11276(normal) ghc/alloc 94,159,364 94,081,640 -0.1% T11303b(normal) ghc/alloc 40,230,059 40,154,368 -0.2% T11822(normal) ghc/alloc 107,424,540 107,346,088 -0.1% T12150(optasm) ghc/alloc 76,486,339 76,426,152 -0.1% T12234(optasm) ghc/alloc 55,585,046 55,507,352 -0.1% T12425(optasm) ghc/alloc 88,343,288 88,265,312 -0.1% T13035(normal) ghc/alloc 98,919,768 98,845,600 -0.1% T13253-spj(normal) ghc/alloc 121,002,153 120,851,040 -0.1% T16190(normal) ghc/alloc 290,313,131 290,074,152 -0.1% T16875(normal) ghc/alloc 34,756,121 34,681,440 -0.2% T17836b(normal) ghc/alloc 45,198,100 45,120,288 -0.2% T17977(normal) ghc/alloc 39,479,952 39,404,112 -0.2% T17977b(normal) ghc/alloc 37,213,035 37,137,728 -0.2% T18140(normal) ghc/alloc 79,430,588 79,350,680 -0.1% T18282(normal) ghc/alloc 128,303,182 128,225,384 -0.1% T18304(normal) ghc/alloc 84,904,713 84,831,952 -0.1% T18923(normal) ghc/alloc 66,817,241 66,731,984 -0.1% T20049(normal) ghc/alloc 86,188,024 86,107,920 -0.1% T5837(normal) ghc/alloc 35,540,598 35,464,568 -0.2% T6048(optasm) ghc/alloc 99,812,171 99,736,032 -0.1% T9198(normal) ghc/alloc 46,380,270 46,304,984 -0.2% geo. mean -0.0% Metric Increase: T3064
-rw-r--r--compiler/GHC/Core/Opt/OccurAnal.hs7
-rw-r--r--compiler/GHC/Core/Opt/Simplify/Utils.hs10
-rw-r--r--testsuite/tests/ghci.debugger/Unboxed.hs10
-rw-r--r--testsuite/tests/ghci.debugger/scripts/print035.script5
-rw-r--r--testsuite/tests/ghci.debugger/scripts/print035.stdout3
5 files changed, 18 insertions, 17 deletions
diff --git a/compiler/GHC/Core/Opt/OccurAnal.hs b/compiler/GHC/Core/Opt/OccurAnal.hs
index bfabae9f51..c5e4dee1a0 100644
--- a/compiler/GHC/Core/Opt/OccurAnal.hs
+++ b/compiler/GHC/Core/Opt/OccurAnal.hs
@@ -1586,7 +1586,9 @@ nodeScore !env new_bndr lb_deps
is_con_app (App f _) = is_con_app f
is_con_app (Lam _ e) = is_con_app e
is_con_app (Tick _ e) = is_con_app e
- is_con_app _ = False
+ is_con_app (Let _ e) = is_con_app e -- let x = let y = blah in (a,b)
+ is_con_app _ = False -- We will float the y out, so treat
+ -- the x-binding as a con-app (#20941)
maxExprSize :: Int
maxExprSize = 20 -- Rather arbitrary
@@ -1935,6 +1937,9 @@ occAnalUnfolding !env is_rec mb_join_arity unf
(WithUsageDetails usage args') = occAnalList env' args
final_usage = markAllManyNonTail (delDetailsList usage bndrs)
`addLamCoVarOccs` bndrs
+ `delDetailsList` bndrs
+ -- delDetailsList; no need to use tagLamBinders because we
+ -- never inline DFuns so the occ-info on binders doesn't matter
unf -> WithUsageDetails emptyDetails unf
diff --git a/compiler/GHC/Core/Opt/Simplify/Utils.hs b/compiler/GHC/Core/Opt/Simplify/Utils.hs
index 409f3176eb..13a8a1b853 100644
--- a/compiler/GHC/Core/Opt/Simplify/Utils.hs
+++ b/compiler/GHC/Core/Opt/Simplify/Utils.hs
@@ -1130,13 +1130,9 @@ getUnfoldingInRuleMatch env
mode = getMode env
id_unf id | unf_is_active id = idUnfolding id
| otherwise = NoUnfolding
- unf_is_active id
- | not (sm_rules mode) = -- active_unfolding_minimal id
- isStableUnfolding (realIdUnfolding id)
- -- Do we even need to test this? I think this InScopeEnv
- -- is only consulted if activeRule returns True, which
- -- never happens if sm_rules is False
- | otherwise = isActive (sm_phase mode) (idInlineActivation id)
+ unf_is_active id = isActive (sm_phase mode) (idInlineActivation id)
+ -- When sm_rules was off we used to test for a /stable/ unfolding,
+ -- but that seems wrong (#20941)
----------------------
activeRule :: SimplMode -> Activation -> Bool
diff --git a/testsuite/tests/ghci.debugger/Unboxed.hs b/testsuite/tests/ghci.debugger/Unboxed.hs
index a285fefb8f..0a886825eb 100644
--- a/testsuite/tests/ghci.debugger/Unboxed.hs
+++ b/testsuite/tests/ghci.debugger/Unboxed.hs
@@ -1,12 +1,10 @@
+{-# LANGUAGE UnboxedTuples #-}
+
+module Unboxed where
+
data Unboxed1 = Unboxed1 (# Int, Bool #)
data Unboxed2 = Unboxed2 (# Int, (# Int, Bool #) #)
o1 = Unboxed1 (# 5, True #)
o2 = Unboxed2 (# 6, (# 7, False #) #)
-
-force_them :: Int
-force_them = x + (if b then 1 else 2) + y + z + (if c then 3 else 4)
- where
- Unboxed1 (# x, b #) = o1
- Unboxed2 (# y, (# z, c #) #) = o2 \ No newline at end of file
diff --git a/testsuite/tests/ghci.debugger/scripts/print035.script b/testsuite/tests/ghci.debugger/scripts/print035.script
index a4511f0908..0fd6139bc0 100644
--- a/testsuite/tests/ghci.debugger/scripts/print035.script
+++ b/testsuite/tests/ghci.debugger/scripts/print035.script
@@ -5,6 +5,7 @@
:l Unboxed
:p o1
:p o2
-force_them
+o1 `seq` ()
+o2 `seq` ()
:p o1
-:p o2 \ No newline at end of file
+:p o2
diff --git a/testsuite/tests/ghci.debugger/scripts/print035.stdout b/testsuite/tests/ghci.debugger/scripts/print035.stdout
index 8f89277ee2..117cd94cb1 100644
--- a/testsuite/tests/ghci.debugger/scripts/print035.stdout
+++ b/testsuite/tests/ghci.debugger/scripts/print035.stdout
@@ -1,5 +1,6 @@
o1 = (_t1::Unboxed1)
o2 = (_t2::Unboxed2)
-23
+()
+()
o1 = Unboxed1 ((#,#) 5 True)
o2 = Unboxed2 ((#,#) 6 ((#,#) 7 False))