Index: clang/lib/Basic/Targets/Mips.h =================================================================== --- clang/lib/Basic/Targets/Mips.h +++ clang/lib/Basic/Targets/Mips.h @@ -79,6 +79,9 @@ CanUseBSDABICalls = Triple.isOSFreeBSD() || Triple.isOSOpenBSD(); +#if LLVM_DISABLE_MIPS_MADD4 + DisableMadd4 = true; +#endif } bool isIEEE754_2008Default() const { @@ -332,6 +335,8 @@ HasMSA = true; else if (Feature == "+nomadd4") DisableMadd4 = true; + else if (Feature == "-nomadd4") + DisableMadd4 = false; else if (Feature == "+fp64") FPMode = FP64; else if (Feature == "-fp64") Index: llvm/CMakeLists.txt =================================================================== --- llvm/CMakeLists.txt +++ 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) Index: llvm/include/llvm/Config/llvm-config.h.cmake =================================================================== --- llvm/include/llvm/Config/llvm-config.h.cmake +++ 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 Index: llvm/lib/Target/Mips/MipsSubtarget.cpp =================================================================== --- llvm/lib/Target/Mips/MipsSubtarget.cpp +++ llvm/lib/Target/Mips/MipsSubtarget.cpp @@ -238,6 +238,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 +261,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; }