[GHC] #12877: Constant propagation with basic unboxed arithmetic instructions

#12877: Constant propagation with basic unboxed arithmetic instructions -------------------------------------+------------------------------------- Reporter: hsyl20 | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I have a program that generates the following core: {{{#!hs main = case t of t0 0## -> ... DEFAULT -> case t0 -# 1## of t1 0## -> ... DEFAUT -> case t1 -# 1## of t2 0## -> ... DEFAULT -> case t2 -# 1## of _ 0## -> ... DEFAULT -> ... }}} I think it would be possible to implement constant propagation to get: {{{#!hs main = case t of _ 0## -> ... 1## -> ... 2## -> ... 3## -> ... DEFAULT -> ... }}} If I'm not mistaken, to do that we could replace occurences of: {{{#!hs case t -# k# of _ n0# -> ... n1# -> ... ... DEFAULT -> f }}} with: {{{#!hs case t of _ (n0#+k#) -> ... -- (ni#+k#) statically computed (n1#+k#) -> ... ... DEFAULT -> f }}} Any guidance on how to implement that would be appreciated. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12877 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12877: Constant propagation with basic unboxed arithmetic instructions -------------------------------------+------------------------------------- Reporter: hsyl20 | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by hsyl20): * Attachment "Variant.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12877 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12877: Constant propagation with basic unboxed arithmetic instructions -------------------------------------+------------------------------------- Reporter: hsyl20 | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by hsyl20): * Attachment "Main.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12877 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12877: Constant propagation with basic unboxed arithmetic instructions -------------------------------------+------------------------------------- Reporter: hsyl20 | Owner: hsyl20 Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by hsyl20): * owner: => hsyl20 Comment: I have attached a small reproducing example. I have a patch for GHC to handle this specific case but I will extend it to other cases before publishing it for review. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12877#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12877: Constant propagation with basic unboxed arithmetic instructions -------------------------------------+------------------------------------- Reporter: hsyl20 | Owner: hsyl20 Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Interesting. I'm all for it. A good place to look is `SimplUtils.mkCase`. One thing it does ("Merge Nested Cases") is very similar to what you have. GHC does this: {{{ case x of A -> ea DEFAULT -> case x of B -> eb C -> ec ===> case x of A -> ea B -> eb C -> ec }}} But as you point out, if you just do your second transformation (after "if I'm not mistaken...") then the ''existing'' case-merging stuff will do the rest. And I think you might be able do to your second transformation just by adding a case to `SimplUtils.mkCase`. Yell if you need help. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12877#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12877: Constant propagation with basic unboxed arithmetic instructions -------------------------------------+------------------------------------- Reporter: hsyl20 | Owner: hsyl20 Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2762 Wiki Page: | -------------------------------------+------------------------------------- Changes (by hsyl20): * status: new => patch * differential: => Phab:D2762 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12877#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12877: Constant propagation with basic unboxed arithmetic instructions
-------------------------------------+-------------------------------------
Reporter: hsyl20 | Owner: hsyl20
Type: feature request | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2762
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12877: Constant propagation with basic unboxed arithmetic instructions -------------------------------------+------------------------------------- Reporter: hsyl20 | Owner: hsyl20 Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2762 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed * milestone: => 8.2.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12877#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC