[commit: ghc] master: Make better use of the x86 addressing mode (0e6bc84)

git at git.haskell.org git at git.haskell.org
Tue Jun 10 20:04:58 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/0e6bc84ca958f6da8c10c2ed489f87d8c4c9b463/ghc

>---------------------------------------------------------------

commit 0e6bc84ca958f6da8c10c2ed489f87d8c4c9b463
Author: Johan Tibell <johan.tibell at gmail.com>
Date:   Sat Jun 7 15:03:29 2014 +0200

    Make better use of the x86 addressing mode
    
    We now emit
    
        movq %rdi,16(%r14,%rsi,8)
    
    instead of
    
        leaq 16(%r14),%rax
        movq %rdi,(%rax,%rsi,8)
    
    This helps e.g. byte array indexing.


>---------------------------------------------------------------

0e6bc84ca958f6da8c10c2ed489f87d8c4c9b463
 compiler/nativeGen/X86/CodeGen.hs | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/compiler/nativeGen/X86/CodeGen.hs b/compiler/nativeGen/X86/CodeGen.hs
index e71a1dd..fa93767 100644
--- a/compiler/nativeGen/X86/CodeGen.hs
+++ b/compiler/nativeGen/X86/CodeGen.hs
@@ -805,6 +805,8 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = do -- dyadic MachOps
         | is32BitInteger y = add_int rep x y
     add_code rep x y = trivialCode rep (ADD size) (Just (ADD size)) x y
       where size = intSize rep
+    -- TODO: There are other interesting patterns we want to replace
+    --     with a LEA, e.g. `(x + offset) + (y << shift)`.
 
     --------------------
     sub_code :: Width -> CmmExpr -> CmmExpr -> NatM Register
@@ -1025,6 +1027,13 @@ getAmode' is32Bit (CmmMachOp (MO_Add rep) [a@(CmmMachOp (MO_Shl _) _),
                                   b@(CmmLit _)])
   = getAmode' is32Bit (CmmMachOp (MO_Add rep) [b,a])
 
+-- Matches: (x + offset) + (y << shift)
+getAmode' _ (CmmMachOp (MO_Add _) [CmmRegOff x offset,
+                                   CmmMachOp (MO_Shl _)
+                                        [y, CmmLit (CmmInt shift _)]])
+  | shift == 0 || shift == 1 || shift == 2 || shift == 3
+  = x86_complex_amode (CmmReg x) y shift (fromIntegral offset)
+
 getAmode' _ (CmmMachOp (MO_Add _) [x, CmmMachOp (MO_Shl _)
                                         [y, CmmLit (CmmInt shift _)]])
   | shift == 0 || shift == 1 || shift == 2 || shift == 3



More information about the ghc-commits mailing list