diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -6715,6 +6715,10 @@ if (DisableSelectToBranch) return false; + // If the SelectOptimize pass is enabled, selects have already been optimized. + if (!getCGPassBuilderOption().DisableSelectOptimize) + return false; + // Find all consecutive select instructions that share the same condition. SmallVector ASI; ASI.push_back(SI); diff --git a/llvm/lib/Target/X86/X86CmovConversion.cpp b/llvm/lib/Target/X86/X86CmovConversion.cpp --- a/llvm/lib/Target/X86/X86CmovConversion.cpp +++ b/llvm/lib/Target/X86/X86CmovConversion.cpp @@ -67,6 +67,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/CGPassBuilderOption.h" #include #include #include @@ -167,6 +168,10 @@ if (!EnableCmovConverter) return false; + // If the SelectOptimize pass is enabled, cmovs have already been optimized. + if (!getCGPassBuilderOption().DisableSelectOptimize) + return false; + LLVM_DEBUG(dbgs() << "********** " << getPassName() << " : " << MF.getName() << "**********\n");