Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/a7e0d4484189d08125083638582a6f8e4ae44801

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

commit a7e0d4484189d08125083638582a6f8e4ae44801
Author: Simon Marlow <marlo...@gmail.com>
Date:   Tue Oct 23 13:05:28 2012 +0100

    a small -fPIC optimisation
    
    (PicBaseReg + lit) + N  ==>  PicBaseReg + (lit+N)

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

 compiler/cmm/CmmOpt.hs |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/compiler/cmm/CmmOpt.hs b/compiler/cmm/CmmOpt.hs
index 8436263..dffd417 100644
--- a/compiler/cmm/CmmOpt.hs
+++ b/compiler/cmm/CmmOpt.hs
@@ -183,6 +183,20 @@ cmmMachOpFoldM dflags mop1@(MO_Add{}) [CmmMachOp 
mop2@(MO_Sub{}) [arg1,arg2], ar
    | not (isLit arg1) && not (isPicReg arg1)
    = Just (cmmMachOpFold dflags mop1 [arg1, cmmMachOpFold dflags mop2 
[arg3,arg2]])
 
+-- special case: (PicBaseReg + lit) + N  ==>  PicBaseReg + (lit+N)
+--
+-- this is better because lit+N is a single link-time constant (e.g. a
+-- CmmLabelOff), so the right-hand expression needs only one
+-- instruction, whereas the left needs two.  This happens when pointer
+-- tagging gives us label+offset, and PIC turns the label into
+-- PicBaseReg + label.
+--
+cmmMachOpFoldM _ MO_Add{} [ CmmMachOp op@MO_Add{} [pic, CmmLit lit]
+                          , CmmLit (CmmInt n rep) ]
+  | isPicReg pic
+  = Just $ CmmMachOp op [pic, CmmLit $ cmmOffsetLit lit off ]
+  where off = fromIntegral (narrowS rep n)
+
 -- Make a RegOff if we can
 cmmMachOpFoldM _ (MO_Add _) [CmmReg reg, CmmLit (CmmInt n rep)]
   = Just $ cmmRegOff reg (fromIntegral (narrowS rep n))



_______________________________________________
Cvs-ghc mailing list
Cvs-ghc@haskell.org
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to