diff options
author | klebinger.andreas@gmx.at <klebinger.andreas@gmx.at> | 2018-01-15 13:52:33 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-01-15 13:53:47 -0500 |
commit | bc383f20ce29c5059d8c9c322246ac38bfb0c2a8 (patch) | |
tree | e8906973266e3c9a784e935be9adb8ccb5570515 | |
parent | 1bf70b2041dc2b7c89565fcb46cad8f151f96790 (diff) | |
download | haskell-bc383f20ce29c5059d8c9c322246ac38bfb0c2a8.tar.gz |
Simplify guard in createSwitchPlan.
Given that we have two unique keys (guaranteed by Map) checking that
`|range| == 1` is faster.
The fact that `x1 == lo` and `x2 == hi` is guaranteed by mkSwitchTargets
which removes values outside of the range.
Test Plan: ci
Reviewers: bgamari, simonmar
Reviewed By: simonmar
Subscribers: rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4295
-rw-r--r-- | compiler/cmm/CmmSwitch.hs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/cmm/CmmSwitch.hs b/compiler/cmm/CmmSwitch.hs index 02a581b061..3edfe5ce68 100644 --- a/compiler/cmm/CmmSwitch.hs +++ b/compiler/cmm/CmmSwitch.hs @@ -266,12 +266,11 @@ createSwitchPlan :: SwitchTargets -> SwitchPlan createSwitchPlan (SwitchTargets _signed _range (Just defLabel) m) | [(x, l)] <- M.toList m = IfEqual x l (Unconditionally defLabel) --- And another common case, matching booleans +-- 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 + | [(x1, l1), (_x2,l2)] <- M.toAscList m + --Checking If |range| = 2 is enough if we have two unique literals + , hi - lo == 1 = 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)) $ |