
#10129: emitCmmLitSwitch could be better -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (CodeGen) | Operating System: Unknown/Multiple Keywords: | Type of failure: None/Unknown Architecture: | Blocked By: Unknown/Multiple | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- This is a spin off #10124. While looking at the code generated for {{{ f :: Int -> Bool f a = case a of 1 -> True 2 -> True 3 -> True 4 -> True 8 -> True 9 -> True 11 -> True 19 -> True _ -> False }}} I noticed this Cmm: {{{ c2tI: if (%MO_S_Lt_W64(_s2sJ::I64, 3)) goto c2tw; else goto c2tx; c2tw: if (%MO_S_Lt_W64(_s2sJ::I64, 2)) goto c2tq; else goto c2tr; c2tq: if (_s2sJ::I64 != 1) goto c2tg; else goto c2th; c2tr: if (_s2sJ::I64 != 2) goto c2tg; else goto c2th; }}} Note that when `c2tr` is reached, we know 2 ≤ _s2sJ < 3, so _s2sJ already is 2, and this check is redundant. `emitCmmLitSwitch` does not take that into account, probably because it also needs to work for floats. I wonder if it isn’t a bit shady to use an if-then-else tree for floats. Maybe for float types, a sequence of equality tests is more suitable. For all other cases, the code generator could make use of "2 ≤ x < 3 ⇒ x = 2" and skip one check. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10129 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler