aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-05-07 19:55:55 +0000
committerChris Lattner <sabre@nondot.org>2004-05-07 19:55:55 +0000
commit260195d2b1a2a3be54d932ccd8da45346bec5676 (patch)
tree886b7b00decba771065d42e937db669d53f7b122 /lib/Target
parentadd68af0314949857697b8dc2ac145dca842c7a1 (diff)
downloadexternal_llvm-260195d2b1a2a3be54d932ccd8da45346bec5676.zip
external_llvm-260195d2b1a2a3be54d932ccd8da45346bec5676.tar.gz
external_llvm-260195d2b1a2a3be54d932ccd8da45346bec5676.tar.bz2
Make comparisons against the null pointer as efficient as integer comparisons
against zero. In particular, don't emit: mov %ESI, 0 cmp %ECX, %ESI instead, emit: test %ECX, %ECX git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13407 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r--lib/Target/X86/InstSelectSimple.cpp9
-rw-r--r--lib/Target/X86/X86ISelSimple.cpp9
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp
index da2175b..4597a82 100644
--- a/lib/Target/X86/InstSelectSimple.cpp
+++ b/lib/Target/X86/InstSelectSimple.cpp
@@ -829,7 +829,14 @@ unsigned ISel::EmitComparison(unsigned OpNum, Value *Op0, Value *Op1,
unsigned Op0r = getReg(Op0, MBB, IP);
// Special case handling of: cmp R, i
- if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
+ if (isa<ConstantPointerNull>(Op1)) {
+ if (OpNum < 2) // seteq/setne -> test
+ BuildMI(*MBB, IP, X86::TEST32rr, 2).addReg(Op0r).addReg(Op0r);
+ else
+ BuildMI(*MBB, IP, X86::CMP32ri, 2).addReg(Op0r).addImm(0);
+ return OpNum;
+
+ } else if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
if (Class == cByte || Class == cShort || Class == cInt) {
unsigned Op1v = CI->getRawValue();
diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp
index da2175b..4597a82 100644
--- a/lib/Target/X86/X86ISelSimple.cpp
+++ b/lib/Target/X86/X86ISelSimple.cpp
@@ -829,7 +829,14 @@ unsigned ISel::EmitComparison(unsigned OpNum, Value *Op0, Value *Op1,
unsigned Op0r = getReg(Op0, MBB, IP);
// Special case handling of: cmp R, i
- if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
+ if (isa<ConstantPointerNull>(Op1)) {
+ if (OpNum < 2) // seteq/setne -> test
+ BuildMI(*MBB, IP, X86::TEST32rr, 2).addReg(Op0r).addReg(Op0r);
+ else
+ BuildMI(*MBB, IP, X86::CMP32ri, 2).addReg(Op0r).addImm(0);
+ return OpNum;
+
+ } else if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
if (Class == cByte || Class == cShort || Class == cInt) {
unsigned Op1v = CI->getRawValue();