summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2007-03-01 13:06:28 +0000
committerSimon Marlow <simonmar@microsoft.com>2007-03-01 13:06:28 +0000
commit090bff7e86dbad7c429532994f3f2fe9d4d8b8ea (patch)
treef3ba3a406bb1f76e234b61b6fbe9d06aa1d0ddb8
parentb511a8e82047c37834d2d4e116199511eb6fd70b (diff)
downloadhaskell-090bff7e86dbad7c429532994f3f2fe9d4d8b8ea.tar.gz
further improvements to the x86/x86_64 NCG
-rw-r--r--compiler/cmm/Cmm.hs2
-rw-r--r--compiler/nativeGen/MachCodeGen.hs22
2 files changed, 24 insertions, 0 deletions
diff --git a/compiler/cmm/Cmm.hs b/compiler/cmm/Cmm.hs
index 06e3d16fab..a6c3ec4b83 100644
--- a/compiler/cmm/Cmm.hs
+++ b/compiler/cmm/Cmm.hs
@@ -200,6 +200,7 @@ data CmmExpr
-- ** is shorthand only, meaning **
-- CmmMachOp (MO_S_Add rep (CmmReg reg) (CmmLit (CmmInt i rep)))
-- where rep = cmmRegRep reg
+ deriving Eq
cmmExprRep :: CmmExpr -> MachRep
cmmExprRep (CmmLit lit) = cmmLitRep lit
@@ -248,6 +249,7 @@ data CmmLit
-- It is also used inside the NCG during when generating
-- position-independent code.
| CmmLabelDiffOff CLabel CLabel Int -- label1 - label2 + offset
+ deriving Eq
cmmLitRep :: CmmLit -> MachRep
cmmLitRep (CmmInt _ rep) = rep
diff --git a/compiler/nativeGen/MachCodeGen.hs b/compiler/nativeGen/MachCodeGen.hs
index fca5be30e5..865d02d753 100644
--- a/compiler/nativeGen/MachCodeGen.hs
+++ b/compiler/nativeGen/MachCodeGen.hs
@@ -1839,6 +1839,9 @@ getAmode (CmmMachOp (MO_Add rep)
&& not (is64BitInteger offset)
= x86_complex_amode x y shift offset
+getAmode (CmmMachOp (MO_Add rep) [x,y])
+ = x86_complex_amode x y 0 0
+
getAmode (CmmLit lit) | not (is64BitLit lit)
= return (Amode (ImmAddr (litToImm lit) 0) nilOL)
@@ -2378,6 +2381,25 @@ assignIntCode pk dst src
#if i386_TARGET_ARCH || x86_64_TARGET_ARCH
-- integer assignment to memory
+
+-- specific case of adding/subtracting an integer to a particular address.
+-- ToDo: catch other cases where we can use an operation directly on a memory
+-- address.
+assignMem_IntCode pk addr (CmmMachOp op [CmmLoad addr2 _,
+ CmmLit (CmmInt i _)])
+ | addr == addr2, pk /= I64 || not (is64BitInteger i),
+ Just instr <- check op
+ = do Amode amode code_addr <- getAmode addr
+ let code = code_addr `snocOL`
+ instr pk (OpImm (ImmInt (fromIntegral i))) (OpAddr amode)
+ return code
+ where
+ check (MO_Add _) = Just ADD
+ check (MO_Sub _) = Just SUB
+ check _ = Nothing
+ -- ToDo: more?
+
+-- general case
assignMem_IntCode pk addr src = do
Amode addr code_addr <- getAmode addr
(code_src, op_src) <- get_op_RI src