[commit: ghc] master: Simplify guard in createSwitchPlan. (bc383f2)

git at git.haskell.org git at git.haskell.org
Mon Jan 15 19:22:52 UTC 2018


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

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

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

commit bc383f20ce29c5059d8c9c322246ac38bfb0c2a8
Author: klebinger.andreas at gmx.at <klebinger.andreas at gmx.at>
Date:   Mon Jan 15 13:52:33 2018 -0500

    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


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

bc383f20ce29c5059d8c9c322246ac38bfb0c2a8
 compiler/cmm/CmmSwitch.hs | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/compiler/cmm/CmmSwitch.hs b/compiler/cmm/CmmSwitch.hs
index 02a581b..3edfe5c 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)) $



More information about the ghc-commits mailing list