diff options
author | Dan Gohman <gohman@apple.com> | 2008-10-17 01:33:43 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2008-10-17 01:33:43 +0000 |
commit | ca0546facc5af4c27a5efd5ff80935ba05ae030a (patch) | |
tree | e41965726caebfa000f4fefdfc491d4ad93cb745 /llvm/lib | |
parent | a39b0a1f05337718973fb9a52df61b302e766109 (diff) | |
download | bcm5719-llvm-ca0546facc5af4c27a5efd5ff80935ba05ae030a.tar.gz bcm5719-llvm-ca0546facc5af4c27a5efd5ff80935ba05ae030a.zip |
Fun x86 encoding tricks: when adding an immediate value of 128,
use a SUB instruction instead of an ADD, because -128 can be
encoded in an 8-bit signed immediate field, while +128 can't be.
This avoids the need for a 32-bit immediate field in this case.
A similar optimization applies to 64-bit adds with 0x80000000,
with the 32-bit signed immediate field.
To support this, teach tablegen how to handle 64-bit constants.
llvm-svn: 57663
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/X86/X86Instr64bit.td | 23 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86InstrInfo.td | 11 |
2 files changed, 26 insertions, 8 deletions
diff --git a/llvm/lib/Target/X86/X86Instr64bit.td b/llvm/lib/Target/X86/X86Instr64bit.td index 5085f54385c..d17ed1a3898 100644 --- a/llvm/lib/Target/X86/X86Instr64bit.td +++ b/llvm/lib/Target/X86/X86Instr64bit.td @@ -61,13 +61,6 @@ def i64immSExt8 : PatLeaf<(i64 imm), [{ return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue(); }]>; -def i64immFFFFFFFF : PatLeaf<(i64 imm), [{ - // i64immFFFFFFFF - True if this is a specific constant we can't write in - // tblgen files. - return N->getZExtValue() == 0x00000000FFFFFFFFULL; -}]>; - - def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>; def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>; def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>; @@ -1323,8 +1316,22 @@ def : Pat<(i32 (anyext GR8:$src)), // Some peepholes //===----------------------------------------------------------------------===// +// Odd encoding trick: -128 fits into an 8-bit immediate field while +// +128 doesn't, so in this special case use a sub instead of an add. +def : Pat<(add GR64:$src1, 128), + (SUB64ri8 GR64:$src1, -128)>; +def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst), + (SUB64mi8 addr:$dst, -128)>; + +// The same trick applies for 32-bit immediate fields in 64-bit +// instructions. +def : Pat<(add GR64:$src1, 0x0000000080000000), + (SUB64ri32 GR64:$src1, 0xffffffff80000000)>; +def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst), + (SUB64mi32 addr:$dst, 0xffffffff80000000)>; + // r & (2^32-1) ==> movz -def : Pat<(and GR64:$src, i64immFFFFFFFF), +def : Pat<(and GR64:$src, 0x00000000FFFFFFFF), (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>; // r & (2^16-1) ==> movz def : Pat<(and GR64:$src, 0xffff), diff --git a/llvm/lib/Target/X86/X86InstrInfo.td b/llvm/lib/Target/X86/X86InstrInfo.td index 16dc366c161..f44b918438a 100644 --- a/llvm/lib/Target/X86/X86InstrInfo.td +++ b/llvm/lib/Target/X86/X86InstrInfo.td @@ -2911,6 +2911,17 @@ def : Pat<(i32 (and (nvloadi32 addr:$src), (i32 65535))), // Some peepholes //===----------------------------------------------------------------------===// +// Odd encoding trick: -128 fits into an 8-bit immediate field while +// +128 doesn't, so in this special case use a sub instead of an add. +def : Pat<(add GR16:$src1, 128), + (SUB16ri8 GR16:$src1, -128)>; +def : Pat<(store (add (loadi16 addr:$dst), 128), addr:$dst), + (SUB16mi8 addr:$dst, -128)>; +def : Pat<(add GR32:$src1, 128), + (SUB32ri8 GR32:$src1, -128)>; +def : Pat<(store (add (loadi32 addr:$dst), 128), addr:$dst), + (SUB32mi8 addr:$dst, -128)>; + // r & (2^16-1) ==> movz def : Pat<(and GR32:$src1, 0xffff), (MOVZX32rr16 (i16 (EXTRACT_SUBREG GR32:$src1, x86_subreg_16bit)))>; |