[GHC] #14282: tagToEnum# . dataToTag# not optimized away

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Keywords: datacon-tags | 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 {{{#!hs foo :: Int# -> Int# foo x = dataToTag# (tagToEnum# x :: Bool) bar :: Bool -> Bool bar x = tagToEnum# (dataToTag# x) }}} These are both effectively identity functions. But while `foo` simplifies to one, `bar` does not! We might want to fix that. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: datacon-tags 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 simonpj): * owner: (none) => dfeuer Comment: Yes, please do. In `PrelRules` I see that `dataToTagRule` has a rule for when the argument is `tagToEnum#`. It should be easy to do the same thing for `tagToEnumRule`. Low impact, but low cost. Thanks. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: datacon-tags 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 dfeuer): I'm trying, but I've hit a snag. Desugaring (even before optimization) produces {{{ bar :: Bool -> Bool [LclIdX] bar = \ (x_aHq :: Bool) -> case dataToTag# @ Bool x_aHq of wild_00 { __DEFAULT -> tagToEnum# @ Bool wild_00 } end Rec } }}} so looking for the application directly doesn't work. Is there a way to look through the unfolding of `wild_00` to see the `dataToTag#`? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: datacon-tags 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 dfeuer): Hrm... I tried that, and it looks like `wild_00` has no unfolding. Is there a way to give it one? Or am I barking up the wrong tree? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: datacon-tags 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): No, case binders don't get that unfolding... doing so might duplicate work. Reason it's case-bound is that it's a can-fail primop; see `Note [dataToTag#]` in `primops.txt.pp`. It's the `let/app invariant` in action. Rats. I suggest you put a comment with `dataToTagRule` explaining why this is tricky and pointing to this ticket, and then leave it. It's tiresome but I don't think it's important enough to merit further investment. (FWIW ultimately I think the right solution might be to make `dataToTag#` CONLIKE, and arrange to give unfoldings to the case binder of a case on a CONLIKE application. But I can't forsee all the consequences of that.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: datacon-tags 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 dfeuer): Yes, I think you're likely right about `CONLIKE` things, unless the inliner will end up actually inlining the applications and lead to some absurdity like `case dataToTag# x of DEFAULT -> case dataToTag# x of DEFAULT -> ....`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: datacon-tags 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 bgamari): dfeuer, what is the status of this? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: datacon-tags Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4375 Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfeuer): * status: new => patch * differential: => Phab:D4375 Comment: I've put up a differential adding the necessary explanation. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14282: tagToEnum# . dataToTag# not optimized away
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: dfeuer
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Compiler | Version: 8.2.1
Resolution: | Keywords: datacon-tags
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4375
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#14282: tagToEnum# . dataToTag# not optimized away
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner: dfeuer
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Compiler | Version: 8.2.1
Resolution: | Keywords: datacon-tags
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4375
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#14282: tagToEnum# . dataToTag# not optimized away -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: dfeuer Type: bug | Status: patch Priority: low | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: datacon-tags Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4375 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * priority: normal => low * milestone: 8.6.1 => Comment: Demilestoning since moving this along further will be nontrivial. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14282#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC