[project @ 2005-07-07 13:50:40 by simonmar]
authorsimonmar <unknown>
Thu, 7 Jul 2005 13:50:40 +0000 (13:50 +0000)
committersimonmar <unknown>
Thu, 7 Jul 2005 13:50:40 +0000 (13:50 +0000)
small performance fix: in via-C mode we previously always created a
switch instead of an conditional-tree for a multi-branch case.  Refine
this slightly so that 2-branch switches turn into conditionals again,
since gcc doesn't do a good job of optimising the equivalent switch.

ghc/compiler/codeGen/CgUtils.hs

index b70bd26..68958d2 100644 (file)
@@ -413,7 +413,7 @@ mk_switch tag_expr [(tag,stmts)] (Just deflt) lo_tag hi_tag via_C
 -- time works around that problem.
 --
 mk_switch tag_expr branches mb_deflt lo_tag hi_tag via_C
-  | use_switch || via_C        -- Use a switch
+  | use_switch         -- Use a switch
   = do { branch_ids <- mapM forkCgStmts (map snd branches)
        ; let 
                tagged_blk_ids = zip (map fst branches) (map Just branch_ids)
@@ -479,7 +479,7 @@ mk_switch tag_expr branches mb_deflt lo_tag hi_tag via_C
                        text "real_lo_tag: " <+> int real_lo_tag <+>
                        text "real_hi_tag: " <+> int real_hi_tag) $ -}
                   ASSERT( n_branches > 1 && n_tags > 1 ) 
-                  n_tags > 2 && (small || dense)
+                  n_tags > 2 && (small || dense || via_C)
                 -- a 2-branch switch always turns into an if.
     small               = n_tags <= 4
     dense               = n_branches > (n_tags `div` 2)