Index: include/llvm/CodeGen/Passes.h =================================================================== --- include/llvm/CodeGen/Passes.h +++ include/llvm/CodeGen/Passes.h @@ -388,7 +396,9 @@ /// createCodeGenPreparePass - Transform the code to expose more pattern /// matching during instruction selection. - FunctionPass *createCodeGenPreparePass(const TargetMachine *TM = nullptr); + FunctionPass *createCodeGenPreparePass(const TargetMachine *TM = nullptr, + bool DisableBranchOpts = false, + bool AddrSinkUsingGEP = false); /// AtomicExpandID -- Lowers atomic operations in terms of either cmpxchg /// load-linked/store-conditional loops. Index: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -69,9 +69,9 @@ STATISTIC(NumAndCmpsMoved, "Number of and/cmp's pushed into branches"); STATISTIC(NumStoreExtractExposed, "Number of store(extractelement) exposed"); -static cl::opt DisableBranchOpts( - "disable-cgp-branch-opts", cl::Hidden, cl::init(false), - cl::desc("Disable branch optimizations in CodeGenPrepare")); +static cl::opt DisableBranchOpts_( + "disable-cgp-branch-opts", cl::Hidden, cl::init(false), + cl::desc("Disable branch optimizations in CodeGenPrepare")); static cl::opt DisableGCOpts("disable-cgp-gc-opts", cl::Hidden, cl::init(false), @@ -81,9 +81,9 @@ "disable-cgp-select2branch", cl::Hidden, cl::init(false), cl::desc("Disable select to branch conversion.")); -static cl::opt AddrSinkUsingGEPs( - "addr-sink-using-gep", cl::Hidden, cl::init(false), - cl::desc("Address sinking in CGP using GEPs.")); +static cl::opt + AddrSinkUsingGEPs_("addr-sink-using-gep", cl::Hidden, cl::init(false), + cl::desc("Address sinking in CGP using GEPs.")); static cl::opt EnableAndCmpSinking( "enable-andcmp-sinking", cl::Hidden, cl::init(true), @@ -125,6 +125,11 @@ const TargetTransformInfo *TTI; const TargetLibraryInfo *TLInfo; + /// Local cached version of the globals options that can be modified in the + /// ctor + bool AddrSinkUsingGEPs; + bool DisableBranchOpts; + /// CurInstIterator - As we scan instructions optimizing them, this is the /// next instruction to optimize. Xforms that can invalidate this should /// update it. @@ -149,8 +154,12 @@ public: static char ID; // Pass identification, replacement for typeid - explicit CodeGenPrepare(const TargetMachine *TM = nullptr) + explicit CodeGenPrepare(const TargetMachine *TM = nullptr, + bool DisableBranchOpt = false, + bool AddrSinkUsingGEP = false) : FunctionPass(ID), TM(TM), TLI(nullptr), TTI(nullptr) { + DisableBranchOpts = DisableBranchOpts_ | DisableBranchOpt; + AddrSinkUsingGEPs = AddrSinkUsingGEPs_ | AddrSinkUsingGEP; initializeCodeGenPreparePass(*PassRegistry::getPassRegistry()); } bool runOnFunction(Function &F) override; @@ -195,8 +204,10 @@ INITIALIZE_TM_PASS(CodeGenPrepare, "codegenprepare", "Optimize for code generation", false, false) -FunctionPass *llvm::createCodeGenPreparePass(const TargetMachine *TM) { - return new CodeGenPrepare(TM); +FunctionPass *llvm::createCodeGenPreparePass(const TargetMachine *TM, + bool DisableBranchOpt, + bool AddrSinkUsingGEP) { + return new CodeGenPrepare(TM, DisableBranchOpt, AddrSinkUsingGEP); } bool CodeGenPrepare::runOnFunction(Function &F) { @@ -226,7 +237,8 @@ // Eliminate blocks that contain only PHI nodes and an // unconditional branch. - EverMadeChange |= EliminateMostlyEmptyBlocks(F); + if (!DisableBranchOpts) + EverMadeChange |= EliminateMostlyEmptyBlocks(F); // llvm.dbg.value is far away from the value then iSel may not be able // handle it properly. iSel will drop llvm.dbg.value if it can not @@ -3317,7 +3329,7 @@ if (SunkAddr->getType() != Addr->getType()) SunkAddr = Builder.CreateBitCast(SunkAddr, Addr->getType()); } else if (AddrSinkUsingGEPs || - (!AddrSinkUsingGEPs.getNumOccurrences() && TM && + (!AddrSinkUsingGEPs_.getNumOccurrences() && TM && TM->getSubtargetImpl(*MemoryInst->getParent()->getParent()) ->useAA())) { // By default, we use the GEP-based method when AA is used later. This