summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2021-02-10 13:41:52 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-02-28 06:10:39 -0500
commitdf2eca94ce8395fb9f52e83d8f3c790317a27c97 (patch)
tree5282dac50f1568da06e4b084ec5f3fc809b26046 /testsuite
parentc3ff35bbd11fd213ec2773bc0a03e2533fda7c1a (diff)
downloadhaskell-df2eca94ce8395fb9f52e83d8f3c790317a27c97.tar.gz
CPR analysis: Use CPR of scrutinee for Case Binder CPR (#19232)
For years we have lived in a supposedly sweet spot that gave case binders the CPR property, unconditionally. Which is an optimistic hack that is now described in `Historical Note [Optimistic case binder CPR]`. In #19232 the concern was raised that this might do more harm than good and that might be better off simply by taking the CPR property of the scrutinee for the CPR type of the case binder. And indeed that's what we do now. Since `Note [CPR in a DataAlt case alternative]` is now only about field binders, I renamed and garbage collected it into `Note [Optimistic field binder CPR]`. NoFib approves: ``` NoFib Results -------------------------------------------------------------------------------- Program Allocs Instrs -------------------------------------------------------------------------------- anna +0.1% +0.1% nucleic2 -1.2% -0.6% sched 0.0% +0.9% transform -0.0% -0.1% -------------------------------------------------------------------------------- Min -1.2% -0.6% Max +0.1% +0.9% Geometric Mean -0.0% +0.0% ``` Fixes #19232.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/cpranal/sigs/CaseBinderCPR.hs (renamed from testsuite/tests/stranal/sigs/CaseBinderCPR.hs)6
-rw-r--r--testsuite/tests/cpranal/sigs/CaseBinderCPR.stderr7
-rw-r--r--testsuite/tests/cpranal/sigs/Makefile3
-rw-r--r--testsuite/tests/cpranal/sigs/T19232.hs14
-rw-r--r--testsuite/tests/cpranal/sigs/T19232.stderr6
-rw-r--r--testsuite/tests/cpranal/sigs/all.T9
-rw-r--r--testsuite/tests/stranal/sigs/CaseBinderCPR.stderr18
-rw-r--r--testsuite/tests/stranal/sigs/all.T1
8 files changed, 45 insertions, 19 deletions
diff --git a/testsuite/tests/stranal/sigs/CaseBinderCPR.hs b/testsuite/tests/cpranal/sigs/CaseBinderCPR.hs
index 13f216347d..1310031f42 100644
--- a/testsuite/tests/stranal/sigs/CaseBinderCPR.hs
+++ b/testsuite/tests/cpranal/sigs/CaseBinderCPR.hs
@@ -13,3 +13,9 @@ f_list_cmp a_cmp (a_x:a_xs) (a_y:a_ys)=
else r_order
where
r_order = a_cmp a_x a_y
+
+
+-- But not every case binder has the CPR property.
+-- x below does not and we should not CPR nestedly for it:
+g :: [Int] -> (Int, Int)
+g xs = let x = xs !! 0 in x `seq` (x, x)
diff --git a/testsuite/tests/cpranal/sigs/CaseBinderCPR.stderr b/testsuite/tests/cpranal/sigs/CaseBinderCPR.stderr
new file mode 100644
index 0000000000..7f98fe0612
--- /dev/null
+++ b/testsuite/tests/cpranal/sigs/CaseBinderCPR.stderr
@@ -0,0 +1,7 @@
+
+==================== Cpr signatures ====================
+CaseBinderCPR.$trModule:
+CaseBinderCPR.f_list_cmp:
+CaseBinderCPR.g: m1
+
+
diff --git a/testsuite/tests/cpranal/sigs/Makefile b/testsuite/tests/cpranal/sigs/Makefile
new file mode 100644
index 0000000000..9101fbd40a
--- /dev/null
+++ b/testsuite/tests/cpranal/sigs/Makefile
@@ -0,0 +1,3 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/testsuite/tests/cpranal/sigs/T19232.hs b/testsuite/tests/cpranal/sigs/T19232.hs
new file mode 100644
index 0000000000..3ea087d585
--- /dev/null
+++ b/testsuite/tests/cpranal/sigs/T19232.hs
@@ -0,0 +1,14 @@
+module T19232 where
+
+-- | `x` is not used strictly and hence will not be available unboxed, so
+-- the `otherwise` RHS does not have the CPR property, even if it returns
+-- a case binder.
+f :: Bool -> Int -> Int
+f True x
+ | x == 3 = 8
+ | otherwise = x -- NB: the condition was flipped so that we can't substitute `x` for a constant here
+f False _ = 3
+{-# NOINLINE f #-}
+
+-- See also test CaseBinderCPR
+
diff --git a/testsuite/tests/cpranal/sigs/T19232.stderr b/testsuite/tests/cpranal/sigs/T19232.stderr
new file mode 100644
index 0000000000..3aa701833b
--- /dev/null
+++ b/testsuite/tests/cpranal/sigs/T19232.stderr
@@ -0,0 +1,6 @@
+
+==================== Cpr signatures ====================
+T19232.$trModule:
+T19232.f:
+
+
diff --git a/testsuite/tests/cpranal/sigs/all.T b/testsuite/tests/cpranal/sigs/all.T
new file mode 100644
index 0000000000..f5ac233a8c
--- /dev/null
+++ b/testsuite/tests/cpranal/sigs/all.T
@@ -0,0 +1,9 @@
+# We are testing the result of an optimization, so no use
+# running them in various runtimes
+setTestOpts(only_ways(['optasm']))
+# This directory contains tests where we annotate functions with expected
+# CPR signatures, and verify that these are actually those found by the compiler
+setTestOpts(extra_hc_opts('-ddump-cpr-signatures'))
+
+test('CaseBinderCPR', normal, compile, [''])
+test('T19232', normal, compile, [''])
diff --git a/testsuite/tests/stranal/sigs/CaseBinderCPR.stderr b/testsuite/tests/stranal/sigs/CaseBinderCPR.stderr
deleted file mode 100644
index ca6d3015ff..0000000000
--- a/testsuite/tests/stranal/sigs/CaseBinderCPR.stderr
+++ /dev/null
@@ -1,18 +0,0 @@
-
-==================== Strictness signatures ====================
-CaseBinderCPR.$trModule:
-CaseBinderCPR.f_list_cmp: <UCU(CS(P(MU)))><SU><SU>
-
-
-
-==================== Cpr signatures ====================
-CaseBinderCPR.$trModule:
-CaseBinderCPR.f_list_cmp: m1
-
-
-
-==================== Strictness signatures ====================
-CaseBinderCPR.$trModule:
-CaseBinderCPR.f_list_cmp: <UCU(CS(P(SU)))><SU><SU>
-
-
diff --git a/testsuite/tests/stranal/sigs/all.T b/testsuite/tests/stranal/sigs/all.T
index 07cc815823..5d562a6a8c 100644
--- a/testsuite/tests/stranal/sigs/all.T
+++ b/testsuite/tests/stranal/sigs/all.T
@@ -16,7 +16,6 @@ test('UnsatFun', normal, compile, [''])
test('BottomFromInnerLambda', normal, compile, [''])
test('DmdAnalGADTs', normal, compile, [''])
test('T12370', normal, compile, [''])
-test('CaseBinderCPR', normal, compile, [''])
test('NewtypeArity', normal, compile, [''])
test('T5075', normal, compile, [''])
test('T17932', normal, compile, [''])