summaryrefslogtreecommitdiff
path: root/compiler/cmm/CmmSwitch.hs
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2015-08-07 10:56:09 +0200
committerJoachim Breitner <mail@joachim-breitner.de>2015-08-08 09:31:03 +0200
commit92f35cd9829db7555397aa3dc8cd243d17694fee (patch)
tree155ae9cc46fd23c5f6ab59bc804371499ccb2ef0 /compiler/cmm/CmmSwitch.hs
parent590aa0f03dda8bb71c7b6910e64aa6e7f951fbbf (diff)
downloadhaskell-92f35cd9829db7555397aa3dc8cd243d17694fee.tar.gz
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
Diffstat (limited to 'compiler/cmm/CmmSwitch.hs')
-rw-r--r--compiler/cmm/CmmSwitch.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/cmm/CmmSwitch.hs b/compiler/cmm/CmmSwitch.hs
index 09abec6f8b..604e759208 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