[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

#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