From 6ed34918ebc2b7bcfcc5e5ee42070303b73811fe Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 12 May 2009 00:07:35 +0000 Subject: [PATCH] Avoid unneeded SIB byte encoding. Patch by Zoltan Varga. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71520 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86CodeEmitter.cpp | 3 ++- lib/Target/X86/X86InstrInfo.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Target/X86/X86CodeEmitter.cpp b/lib/Target/X86/X86CodeEmitter.cpp index c21eacc9a4c..63bf18d157f 100644 --- a/lib/Target/X86/X86CodeEmitter.cpp +++ b/lib/Target/X86/X86CodeEmitter.cpp @@ -338,7 +338,8 @@ void Emitter::emitMemModRMByte(const MachineInstr &MI, unsigned BaseReg = Base.getReg(); // Is a SIB byte needed? - if ((!Is64BitMode || DispForReloc) && IndexReg.getReg() == 0 && + if ((!Is64BitMode || DispForReloc || BaseReg != 0) && + IndexReg.getReg() == 0 && (BaseReg == 0 || getX86RegNum(BaseReg) != N86::ESP)) { if (BaseReg == 0) { // Just a displacement? // Emit special case [disp32] encoding diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index 369c4c6e7e0..85756a1cdcd 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -2811,7 +2811,8 @@ static unsigned getMemModRMByteSize(const MachineInstr &MI, unsigned Op, unsigned BaseReg = Base.getReg(); // Is a SIB byte needed? - if ((!Is64BitMode || DispForReloc) && IndexReg.getReg() == 0 && + if ((!Is64BitMode || DispForReloc || BaseReg != 0) && + IndexReg.getReg() == 0 && (BaseReg == 0 || X86RegisterInfo::getX86RegNum(BaseReg) != N86::ESP)) { if (BaseReg == 0) { // Just a displacement? // Emit special case [disp32] encoding