[GHC] #10129: emitCmmLitSwitch could be better
#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
#10129: emitCmmLitSwitch could be better -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: task | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (CodeGen) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D693 -------------------------------------+------------------------------------- Changes (by nomeata): * status: new => patch * differential: => Phab:D693 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10129#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10129: emitCmmLitSwitch could be better -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: task | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (CodeGen) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | Blocking: Blocked By: | Differential Revisions: Phab:D693 Related Tickets: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: bgamari (added) * failure: None/Unknown => Runtime performance bug -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10129#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10129: emitCmmLitSwitch could be better -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: task | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (CodeGen) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | Blocking: Blocked By: | Differential Revisions: Phab:D693 Related Tickets: | -------------------------------------+------------------------------------- Comment (by Joachim Breitner <mail@…>): In [changeset:"c3eee14d31585445d4a7eff5b6c69a815b911059/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="c3eee14d31585445d4a7eff5b6c69a815b911059" Improve if-then-else tree for cases on literal values Previously, in the branch of the if-then-else tree, it would emit a final check if the scrut matches the alternative, even if earlier comparisons alread imply this equality. By keeping track of the bounds we can skip this check. Of course this is only sound for integer types. This closes #10129. Differential Revision: https://phabricator.haskell.org/D693 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10129#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10129: emitCmmLitSwitch could be better -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: task | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (CodeGen) | Keywords: Resolution: fixed | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | Blocking: Blocked By: | Differential Revisions: Phab:D693 Related Tickets: | -------------------------------------+------------------------------------- Changes (by nomeata): * status: patch => closed * resolution: => fixed Comment: This bit is done. It would still be nice to unify `emitCmmLitSwitch` with `emitSwitch`, but maybe some other day. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10129#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10129: emitCmmLitSwitch could be better -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: task | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (CodeGen) | Keywords: Resolution: fixed | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | Blocking: Blocked By: | Differential Revisions: Phab:D693 Related Tickets: | -------------------------------------+------------------------------------- Comment (by simonpj): Regression test? Maybe too awkward... -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10129#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10129: emitCmmLitSwitch could be better -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: task | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (CodeGen) | Keywords: Resolution: fixed | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: Runtime | Test Case: performance bug | Blocking: Blocked By: | Differential Revisions: Phab:D693 Related Tickets: | -------------------------------------+------------------------------------- Comment (by nomeata): I thought about this, but I’m really not sure how to do it. The best thing I could think of would be to grep on the output of -ddump-cmm, but that seems too fragile. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10129#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC