[GHC] #12982: Missed constant folding oportunities

#12982: Missed constant folding oportunities -------------------------------------+------------------------------------- Reporter: erikd | Owner: Type: feature | Status: new request | Priority: normal | Milestone: 8.4.1 Component: | Version: 8.0.1 libraries/hoopl | 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: -------------------------------------+------------------------------------- A work colleague of mine found that some expressions were not being constant folded as expected. For example: {{#!hs module Test where import Data.Int number :: Int64 number = 2 ^ 10 - 3 }}} compiled using: {{{ ghc -O2 -keep-s-file -c test.hs }}} should result in an assembler file containing the constant `1021` but doesn't. However, if I change the above expression to: {{{ number = 1024 -3 }}} then the output assembler files does contain the value `1021`. I did a bit of a search and found some constant folding code in the `hoopl` library, but that doesn't seem to be what GHC actually uses. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12982 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12982: Missed constant folding oportunities -------------------------------------+------------------------------------- Reporter: erikd | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: libraries/hoopl | 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: | -------------------------------------+------------------------------------- @@ -5,1 +5,1 @@ - {{#!hs + {{{#!hs New description: A work colleague of mine found that some expressions were not being constant folded as expected. For example: {{{#!hs module Test where import Data.Int number :: Int64 number = 2 ^ 10 - 3 }}} compiled using: {{{ ghc -O2 -keep-s-file -c test.hs }}} should result in an assembler file containing the constant `1021` but doesn't. However, if I change the above expression to: {{{ number = 1024 -3 }}} then the output assembler files does contain the value `1021`. I did a bit of a search and found some constant folding code in the `hoopl` library, but that doesn't seem to be what GHC actually uses. -- Comment (by simonpj): I suspect it's just that the constant folding RULES, in `prelude/Build -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12982#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12982: Missed constant folding oportunities -------------------------------------+------------------------------------- Reporter: erikd | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: libraries/hoopl | 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 sio):
Would anyone like to fix that? (Need to be careful to preserve overflow behaviour.)
I'd like to take a crack at this. It'll be my first change, so will take me a while to get familiar with the codebase; will update when I've made some progress. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12982#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12982: Missed constant folding oportunities -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: libraries/hoopl | Version: 8.0.1 Resolution: | Keywords: newcomer 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 bgamari): * keywords: => newcomer * milestone: 8.6.1 => Comment: sio, sorry I missed your comment; were you able to make any progress on this? Do ping if you need help. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12982#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12982: Missed constant folding oportunities -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: libraries/hoopl | Version: 8.0.1 Resolution: | Keywords: newcomer 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 Vyse007): I took a stab at this: thanks to Ben I was able to add a new {{{ PrimOp}}} for POW, along with some basic rules for folding in {{{ PrelRules.hs}}}. I eventually found myself stuck in {{{nativeGen/X86/CodeGen.hs}}} where we employ {{{getRegister}}} to find free registers for computation. I couldn't grok all of it so for I just copied the {{{triv_op}}} call for {{{MO_Mul}}} and it seemed to work fine; I understand that it's incorrect obviously, but I might need a little help in understanding what's the best solution. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12982#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12982: Missed constant folding oportunities -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: libraries/hoopl | Version: 8.0.1 Resolution: | Keywords: newcomer 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): Hi Vyse007, do you think you could push your patch to Phabricator so I can have a look. Thanks for picking this up! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12982#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC