diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -462,6 +462,12 @@ endif() endif( LLVM_USE_INTEL_JITEVENTS ) +# Loongson has bug on madd.fmt/msub.fmt instructions. gcc has a buildtime option: --without-madd4/--with-madd4 +# Users can still enable/disable madd.fmt/msub.fmt when runtime with option: -mmadd4/-mno-madd4 +option(LLVM_DISABLE_MIPS_MADD4 + "Disable MIPS madd.fmt/msub.fmt instructions by default." + OFF) + option(LLVM_USE_OPROFILE "Use opagent JIT interface to inform OProfile about JIT code" OFF) diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -56,6 +56,9 @@ /* Define if we have the Intel JIT API runtime support library */ #cmakedefine01 LLVM_USE_INTEL_JITEVENTS +/* Define if wish disable MIPS madd.fmt/msub.fmt instructions by default. */ +#cmakedefine01 LLVM_DISABLE_MIPS_MADD4 + /* Define if we have the oprofile JIT-support library */ #cmakedefine01 LLVM_USE_OPROFILE diff --git a/llvm/lib/Target/Mips/MipsSubtarget.cpp b/llvm/lib/Target/Mips/MipsSubtarget.cpp --- a/llvm/lib/Target/Mips/MipsSubtarget.cpp +++ b/llvm/lib/Target/Mips/MipsSubtarget.cpp @@ -91,6 +91,9 @@ if (MipsArchVersion == MipsDefault) MipsArchVersion = Mips32; + if (hasMips32r6() || hasMips64r6()) + DisableMadd4 = false; + // Don't even attempt to generate code for MIPS-I and MIPS-V. They have not // been tested and currently exist for the integrated assembler only. if (MipsArchVersion == Mips1) @@ -238,6 +241,7 @@ MipsSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS, const TargetMachine &TM) { StringRef CPUName = MIPS_MC::selectMipsCPU(TM.getTargetTriple(), CPU); + SubtargetFeatures Features(FS); // Parse features string. ParseSubtargetFeatures(CPUName, FS); @@ -260,6 +264,16 @@ report_fatal_error("64-bit code requested on a subtarget that doesn't " "support it!"); +#if LLVM_DISABLE_MIPS_MADD4 + DisableMadd4 = true; +#endif + for (const std::string &Feature : Features.getFeatures()) { + if (Feature == "+nomadd4") + DisableMadd4 = true; + else if (Feature == "-nomadd4") + DisableMadd4 = false; + } + return *this; }