[GHC] #5598: Function quotRem is inefficient

GHC cvs-ghc at haskell.org
Thu Feb 16 11:58:06 CET 2012


#5598: Function quotRem is inefficient
----------------------------------------------+-----------------------------
    Reporter:  boris                          |       Owner:  igloo                  
        Type:  task                           |      Status:  new                    
    Priority:  normal                         |   Milestone:  7.6.1                  
   Component:  Compiler                       |     Version:  7.0.3                  
    Keywords:  division, performance, primop  |          Os:  Unknown/Multiple       
Architecture:  x86                            |     Failure:  Runtime performance bug
  Difficulty:  Unknown                        |    Testcase:                         
   Blockedby:                                 |    Blocking:                         
     Related:                                 |  
----------------------------------------------+-----------------------------

Comment(by boris):

 Thank you for fixing this. Despite LLVM does not have a div-like command,
 we can help it to optimize the second division away by replacing two loads
 with one.

 Actual:

 {{{
 %ln1ot = load i64* %ls1ln
 %ln1ou = srem i64 %ln1ot, 123
 store i64 %ln1ou, i64* %ls1lW
 %ln1ov = load i64* %ls1ln
 %ln1ow = sdiv i64 %ln1ov, 123
 store i64 %ln1ow, i64* %ls1lV
 }}}


 Expected:

 {{{
 %ln1ot = load i64* %ls1ln
 %ln1ou = srem i64 %ln1ot, 123
 store i64 %ln1ou, i64* %ls1lW
 %ln1ow = sdiv i64 %ln1ot, 123
 store i64 %ln1ow, i64* %ls1lV
 }}}


 Perhaps this optimization can be generalized further as sharing load
 command for multiple adjacent primops. Some time ago I saw several loads
 from one memory location in LLVM assembly not related to division.

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



More information about the Glasgow-haskell-bugs mailing list