[commit: ghc] master: cmmCreateSwitchPlan: Handle singletons up-front (92f35cd)

git at git.haskell.org git at git.haskell.org
Sat Aug 8 07:30:31 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/92f35cd9829db7555397aa3dc8cd243d17694fee/ghc

>---------------------------------------------------------------

commit 92f35cd9829db7555397aa3dc8cd243d17694fee
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Fri Aug 7 10:56:09 2015 +0200

    cmmCreateSwitchPlan: Handle singletons up-front
    
    and make sure these are implemented with an equality check, which is a
    shorter instruction. This was suggested by rwbarton in #10677.
    
    Differential Revision: https://phabricator.haskell.org/D1137


>---------------------------------------------------------------

92f35cd9829db7555397aa3dc8cd243d17694fee
 compiler/cmm/CmmSwitch.hs           | 15 +++++++++++++--
 testsuite/tests/perf/compiler/all.T |  4 +++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/compiler/cmm/CmmSwitch.hs b/compiler/cmm/CmmSwitch.hs
index 09abec6..604e759 100644
--- a/compiler/cmm/CmmSwitch.hs
+++ b/compiler/cmm/CmmSwitch.hs
@@ -258,12 +258,23 @@ targetSupportsSwitch _ = False
 -- | This function creates a SwitchPlan from a SwitchTargets value, breaking it
 -- down into smaller pieces suitable for code generation.
 createSwitchPlan :: SwitchTargets -> SwitchPlan
-createSwitchPlan (SwitchTargets signed mbdef range m) =
+-- Lets do the common case of a singleton map quicky and efficiently (#10677)
+createSwitchPlan (SwitchTargets _signed _range (Just defLabel) m)
+    | [(x, l)] <- M.toList m
+    = IfEqual x l (Unconditionally defLabel)
+-- And another common case, matching booleans
+createSwitchPlan (SwitchTargets _signed (lo,hi) Nothing m)
+    | [(x1, l1), (x2,l2)] <- M.toAscList m
+    , x1 == lo
+    , x2 == hi
+    , x1 + 1 == x2
+    = IfEqual x1 l1 (Unconditionally l2)
+createSwitchPlan (SwitchTargets signed range mbdef m) =
     -- pprTrace "createSwitchPlan" (text (show ids) $$ text (show (range,m)) $$ text (show pieces) $$ text (show flatPlan) $$ text (show plan)) $
     plan
   where
     pieces = concatMap breakTooSmall $ splitAtHoles maxJumpTableHole m
-    flatPlan = findSingleValues $ mkFlatSwitchPlan signed range mbdef pieces
+    flatPlan = findSingleValues $ mkFlatSwitchPlan signed mbdef range pieces
     plan = buildTree signed $ flatPlan
 
 
diff --git a/testsuite/tests/perf/compiler/all.T b/testsuite/tests/perf/compiler/all.T
index 66b13bd..affc267 100644
--- a/testsuite/tests/perf/compiler/all.T
+++ b/testsuite/tests/perf/compiler/all.T
@@ -416,7 +416,7 @@ test('T783',
             # 2014-09-03: 223377364 (Windows) better specialisation, raft of core-to-core optimisations
             # 2014-12-22: 235002220 (Windows) not sure why
 
-           (wordsize(64), 548288760, 10)]),
+           (wordsize(64), 470738808, 10)]),
             # prev:       349263216 (amd64/Linux)
             # 07/08/2012: 384479856 (amd64/Linux)
             # 29/08/2012: 436927840 (amd64/Linux)
@@ -437,6 +437,8 @@ test('T783',
 	    #    this test seems to be an extreme outlier.)
             # 2015-05-16: 548288760  (amd64/Linux)
 	    #   (improved sequenceBlocks in nativeCodeGen, #10422)
+            # 2015-08-07: 470738808  (amd64/Linux)
+	    #   (simplifying the switch plan code path for simple checks, #10677)
       extra_hc_opts('-static')
       ],
       compile,[''])



More information about the ghc-commits mailing list