[GHC] #14186: CSE fails to CSE
#14186: CSE fails to CSE -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 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: -------------------------------------+------------------------------------- Consider this code: {{{ module CSEBug where data Succs a = Succs a [a] instance Functor Succs where fmap f (Succs o s) = Succs (f o) (map f s) foo, bar :: (a -> b) -> (b -> c) -> Succs a -> Succs c foo f g x = fmap (g . f) x bar f g x = fmap (g . f) x }}} If I compile this with `-O`, `foo` and `bar` are not CSEd, which can be seen with `-ddump-cse`. Removing either the first or the second argument of `Succs` makes CSE work. Is there a size limit on CSE? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14186: CSE fails to CSE two identical large top-level functions -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 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: | -------------------------------------+------------------------------------- -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14186: CSE fails to CSE two identical large top-level functions -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 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): Ha ha. This is caused by two things 1. We don't CSE things with an INLINE pragma: see `Note [CSE for INLINE and NOINLINE]` in `CSE.hs` 2. The worker/wrapper pass (right after demand analysis) gives the wrapper an inline pragma of `INLINE[0]`. So (2) means that (1) means no CSE for `foo` and `bar`. Sigh. What to do? Well * `InlinePragma` already distinguishse between the `inl_inline` field and `inl_act`. See `Note [inl_inline and inl_act]` in `BasicTypes`. * So we should be able to distinguish between a user-supplied INLINE pragma `inl_inline` and one supplied the w/w pass. * If we could distinguish then CSDE could fail on the user-supplied kind, but succeed on the w/w supplied kind. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14186: CSE fails to CSE two identical large top-level functions -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 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 nomeata):
So we should be able to distinguish between a user-supplied INLINE pragma inl_inline and one supplied the w/w pass.
Are you saying that we can do that already, without changes to `BasicTypes`, or that we should extend `BasicTypes` to be able to do that? The current code in WorkWrap is {{{ wrap_act = ActiveAfter NoSourceText 0 wrap_prag = InlinePragma { inl_src = SourceText "{-# INLINE" , inl_inline = Inline , inl_sat = Nothing , inl_act = wrap_act , inl_rule = rule_match_info } }}} and unless I check for `NoSourceText`, this seems to be indistinguishable from a `INLINE[0]` in the source. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14186: CSE fails to CSE two identical large top-level functions -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 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): I think perhaps the `wrap_prag` can be `EmptyInlineSpec`. That might do it. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14186: CSE fails to CSE two identical large top-level functions -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.3 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:D3939 Wiki Page: | -------------------------------------+------------------------------------- Changes (by nomeata): * status: new => patch * differential: => Phab:D3939 Comment: Phab:D3939 has a flight train result. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14186: CSE fails to CSE two identical large top-level functions -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: CSE Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13589 | Differential Rev(s): Phab:D3939 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * keywords: => CSE * related: => #13589 Old description:
Consider this code:
{{{ module CSEBug where
data Succs a = Succs a [a]
instance Functor Succs where fmap f (Succs o s) = Succs (f o) (map f s)
foo, bar :: (a -> b) -> (b -> c) -> Succs a -> Succs c foo f g x = fmap (g . f) x bar f g x = fmap (g . f) x }}}
If I compile this with `-O`, `foo` and `bar` are not CSEd, which can be seen with `-ddump-cse`.
Removing either the first or the second argument of `Succs` makes CSE work.
Is there a size limit on CSE?
New description: Consider this code: {{{#!hs module CSEBug where data Succs a = Succs a [a] instance Functor Succs where fmap f (Succs o s) = Succs (f o) (map f s) foo, bar :: (a -> b) -> (b -> c) -> Succs a -> Succs c foo f g x = fmap (g . f) x bar f g x = fmap (g . f) x }}} If I compile this with `-O`, `foo` and `bar` are not CSEd, which can be seen with `-ddump-cse`. Removing either the first or the second argument of `Succs` makes CSE work. Is there a size limit on CSE? -- Comment: #131589 is also somewhat relevant here. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14186: CSE fails to CSE two identical large top-level functions -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: CSE Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13589 | Differential Rev(s): Phab:D3939 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Joachim Breitner <mail@…>): In [changeset:"fe35b85a8cc72582e0f98a3059be00a9a2318a4a/ghc" fe35b85a/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="fe35b85a8cc72582e0f98a3059be00a9a2318a4a" Add testcase for #14186 and move the generally useful helpers check_errmsg and grep_errmsg to testlib.py. Some documentation can be found on https://ghc.haskell.org/trac/ghc/wiki/Building/RunningTests/Adding }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14186: CSE fails to CSE two identical large top-level functions -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: CSE Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13589 | Differential Rev(s): Phab:D3939 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Joachim Breitner <mail@…>): In [changeset:"fe04f3783b662c52c4a0ff36b2d62a7a575998a5/ghc" fe04f378/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="fe04f3783b662c52c4a0ff36b2d62a7a575998a5" Allow CSE'ing of work-wrapped bindings (#14186) the worker/wrapper creates an artificial INLINE pragma, which caused CSE to not do its work. We now recognize such artificial pragmas by using `NoUserInline` instead of `Inline` as the `InlineSpec`. Differential Revision: https://phabricator.haskell.org/D3939 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14186#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC