Commit 92f35cd9 authored by Joachim Breitner's avatar Joachim Breitner

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
parent 590aa0f0
......@@ -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
......
......@@ -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,[''])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment