diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -6084,15 +6084,16 @@ // x86-32 PIC requires a PIC base register for constant pools. unsigned PICBase = 0; - if (MF.getTarget().isPositionIndependent()) { - if (Subtarget.is64Bit()) - PICBase = X86::RIP; - else - // FIXME: PICBase = getGlobalBaseReg(&MF); - // This doesn't work for several reasons. - // 1. GlobalBaseReg may have been spilled. - // 2. It may not be live at MI. - return nullptr; + // Since we're using Small or Kernel code model, we can always use + // RIP-relative addressing for a smaller encoding. + if (Subtarget.is64Bit()) { + PICBase = X86::RIP; + } else if (MF.getTarget().isPositionIndependent()) { + // FIXME: PICBase = getGlobalBaseReg(&MF); + // This doesn't work for several reasons. + // 1. GlobalBaseReg may have been spilled. + // 2. It may not be live at MI. + return nullptr; } // Create a constant-pool entry.