[GHC] #14971: Use appropriatly sized comparison instruction for small values.

GHC ghc-devs at haskell.org
Sun Mar 25 10:36:46 UTC 2018


#14971: Use appropriatly sized comparison instruction for small values.
-------------------------------------+-------------------------------------
           Reporter:  AndreasK       |             Owner:  (none)
               Type:  task           |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:
  (CodeGen)                          |
           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:
-------------------------------------+-------------------------------------
 GHC currently defaults all comparisons originating from Cmm switch
 statements to 64bit on x64.

 This incurs a small overhead in instruction size. Fixing this manually
 gave a speedup of ~1,5% in microbenchmarks.

 In detail we generate Cmm of the form:

 {{{
       _s8Dg::P64 = R1;
       _c8EF::P64 = _s8Dg::P64 & 7;
       switch [1 .. 2] _c8EF::P64 {
           case 1 : goto c8Ey;
           case 2 : goto c8EC;
       }
 }}}

 Which results in assembly like:
 {{{
         andl $7,%ebx
         cmpq $1,%rbx
 }}}


 It's obvious that c8EF fits into a byte, but is sized up to 64 bits.
 Changing this would enable us to use cmpl instead of cmpq and save us a
 byte on each comparison.

 While this isn't major in my microbenchmarks it resultet in a speedup of
 ~1,5% for such constructs in inner loops.

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


More information about the ghc-tickets mailing list