From 397ef49cc353599f37292d3f79d42040297312d4 Mon Sep 17 00:00:00 2001 From: simonmar Date: Sun, 3 Apr 2005 22:06:15 +0000 Subject: [PATCH] [project @ 2005-04-03 22:06:15 by simonmar] x86_64: some small optimisations to instruction selection, taking advantage of automatic zero-extension of 32-bit results. --- ghc/compiler/nativeGen/MachCodeGen.hs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/ghc/compiler/nativeGen/MachCodeGen.hs b/ghc/compiler/nativeGen/MachCodeGen.hs index 7837e20..84d6d0d 100644 --- a/ghc/compiler/nativeGen/MachCodeGen.hs +++ b/ghc/compiler/nativeGen/MachCodeGen.hs @@ -1216,11 +1216,35 @@ getRegister (CmmLoad mem pk) getRegister (CmmLit (CmmInt 0 rep)) = let + -- x86_64: 32-bit xor is one byte shorter, and zero-extends to 64 bits + adj_rep = case rep of I64 -> I32; _ -> rep + rep1 = IF_ARCH_i386( rep, adj_rep ) code dst - = unitOL (XOR rep (OpReg dst) (OpReg dst)) + = unitOL (XOR rep1 (OpReg dst) (OpReg dst)) in return (Any rep code) +#if x86_64_TARGET_ARCH + -- optimisation for loading small literals on x86_64: take advantage + -- of the automatic zero-extension from 32 to 64 bits, because the 32-bit + -- instruction forms are shorter. +getRegister (CmmLit lit) + | I64 <- cmmLitRep lit, not (isBigLit lit) + = let + imm = litToImm lit + code dst = unitOL (MOV I32 (OpImm imm) (OpReg dst)) + in + return (Any I64 code) + where + isBigLit (CmmInt i I64) = i < 0 || i > 0xffffffff + isBigLit _ = False + -- note1: not the same as is64BitLit, because that checks for + -- signed literals that fit in 32 bits, but we want unsigned + -- literals here. + -- note2: all labels are small, because we're assuming the + -- small memory model (see gcc docs, -mcmodel=small). +#endif + getRegister (CmmLit lit) = let rep = cmmLitRep lit @@ -2026,6 +2050,8 @@ getRegOrMem e = do #if x86_64_TARGET_ARCH is64BitLit (CmmInt i I64) = i > 0x7fffffff || i < -0x80000000 + -- assume that labels are in the range 0-2^31-1: this assumes the + -- small memory model (see gcc docs, -mcmodel=small). #endif is64BitLit x = False #endif -- 1.7.10.4