diff --git a/lib/Target/Mips/MipsAsmPrinter.cpp b/lib/Target/Mips/MipsAsmPrinter.cpp index 54a97b55f30..e94519e7483 100644 --- a/lib/Target/Mips/MipsAsmPrinter.cpp +++ b/lib/Target/Mips/MipsAsmPrinter.cpp @@ -710,9 +710,14 @@ void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) { getTargetStreamer().updateABIInfo(*Subtarget); getTargetStreamer().emitDirectiveModuleFP(); - if (Subtarget->isABI_O32()) - getTargetStreamer().emitDirectiveModuleOddSPReg(Subtarget->useOddSPReg(), - Subtarget->isABI_O32()); + // If we are targeting O32 then we must emit a '.module [no]oddspreg' ... + if (Subtarget->isABI_O32()) { + // ... but don't emit it unless we are contradicting the default or an + // option has changed the default (i.e. FPXX). + if (!Subtarget->useOddSPReg() || Subtarget->isABI_FPXX()) + getTargetStreamer().emitDirectiveModuleOddSPReg(Subtarget->useOddSPReg(), + Subtarget->isABI_O32()); + } } void MipsAsmPrinter::EmitJal(MCSymbol *Symbol) { diff --git a/test/CodeGen/Mips/no-odd-spreg.ll b/test/CodeGen/Mips/no-odd-spreg.ll index b42ed6aaa40..572e940bc46 100644 --- a/test/CodeGen/Mips/no-odd-spreg.ll +++ b/test/CodeGen/Mips/no-odd-spreg.ll @@ -1,10 +1,14 @@ -; RUN: llc -march=mipsel -mcpu=mips32 < %s | FileCheck %s -check-prefix=ALL -check-prefix=ODDSPREG +; RUN: llc -march=mipsel -mcpu=mips32 < %s | FileCheck %s -check-prefix=ALL -check-prefix=ODDSPREG -check-prefix=ODDSPREG-NO-EMIT ; RUN: llc -march=mipsel -mcpu=mips32 -mattr=+nooddspreg < %s | FileCheck %s -check-prefix=ALL -check-prefix=NOODDSPREG -; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fp64 < %s | FileCheck %s -check-prefix=ALL -check-prefix=ODDSPREG +; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fp64 < %s | FileCheck %s -check-prefix=ALL -check-prefix=ODDSPREG -check-prefix=ODDSPREG-NO-EMIT ; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fp64,+nooddspreg < %s | FileCheck %s -check-prefix=ALL -check-prefix=NOODDSPREG +; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fpxx,-nooddspreg < %s | FileCheck %s -check-prefix=ALL -check-prefix=ODDSPREG -check-prefix=ODDSPREG-EMIT -; ODDSPREG: .module oddspreg -; NOODDSPREG: .module nooddspreg +; We don't emit a directive unless we need to. This is to support versions of +; GAS which do not support the directive. +; ODDSPREG-EMIT: .module oddspreg +; ODDSPREG-NO-EMIT-NOT: .module oddspreg +; NOODDSPREG: .module nooddspreg define float @two_floats(float %a) { entry: