[GHC] #9246: GHC generates poor code for repeated uses of min/max

GHC ghc-devs at haskell.org
Mon Jun 30 02:41:13 UTC 2014


#9246: GHC generates poor code for repeated uses of min/max
--------------------------------------------+------------------------------
        Reporter:  arotenberg               |            Owner:
            Type:  bug                      |           Status:  new
        Priority:  normal                   |        Milestone:
       Component:  Compiler                 |          Version:  7.8.2
      Resolution:                           |         Keywords:
Operating System:  Windows                  |     Architecture:  x86_64
 Type of failure:  Runtime performance bug  |  (amd64)
       Test Case:                           |       Difficulty:  Unknown
        Blocking:                           |       Blocked By:
                                            |  Related Tickets:  #6135
--------------------------------------------+------------------------------

Comment (by arotenberg):

 You should be able to reproduce the issue by using the versions and flags
 I listed in the original description with a fresh GHC 7.8.2 install.

 I'm in no rush to get this fixed since the program I'm working on is just
 a hobby project. I just ran into the issue and figured I'd report it.

 I mentioned "min/max-like functions" in my previous comment because it's
 easy to contrive other functions that cause similar issues. Try compiling
 this module with `ghc -O -ddump-simpl -ddump-to-file UglyBranching.hs` and
 look at the Core file it generates.

 {{{
 module UglyBranching where

 foo :: Int -> Int -> Int -> Int -> Int
 foo a b c d =
     (((a `bar` b) `bar` (c `bar` d)) `bar` ((a `bar` c) `bar` (b `bar`
 d))) `bar`
     (((b `bar` a) `bar` (d `bar` c)) `bar` ((c `bar` a) `bar` (d `bar`
 b)))
 bar :: Int -> Int -> Int
 bar m n = if m + n > 5 then m else n
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9246#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list