Index: llvm/include/llvm/Transforms/Utils/Local.h =================================================================== --- llvm/include/llvm/Transforms/Utils/Local.h +++ llvm/include/llvm/Transforms/Utils/Local.h @@ -66,18 +66,25 @@ bool ConvertSwitchToLookupTable; bool NeedCanonicalLoop; bool SinkCommonInsts; + bool SimplifyCondBranch; + bool FoldTwoEntryPHINode; + AssumptionCache *AC; SimplifyCFGOptions(unsigned BonusThreshold = 1, bool ForwardSwitchCond = false, bool SwitchToLookup = false, bool CanonicalLoops = true, bool SinkCommon = false, - AssumptionCache *AssumpCache = nullptr) + AssumptionCache *AssumpCache = nullptr, + bool SimplifyCondBranch = true, + bool FoldTwoEntryPHINode = true) : BonusInstThreshold(BonusThreshold), ForwardSwitchCondToPhi(ForwardSwitchCond), ConvertSwitchToLookupTable(SwitchToLookup), NeedCanonicalLoop(CanonicalLoops), SinkCommonInsts(SinkCommon), + SimplifyCondBranch(SimplifyCondBranch), + FoldTwoEntryPHINode(FoldTwoEntryPHINode), AC(AssumpCache) {} // Support 'builder' pattern to set members by name at construction time. @@ -105,6 +112,15 @@ AC = Cache; return *this; } + SimplifyCFGOptions &setSimplifyCondBranch(bool B) { + SimplifyCondBranch = B; + return *this; + } + + SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) { + FoldTwoEntryPHINode = B; + return *this; + } }; //===----------------------------------------------------------------------===// Index: llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -281,6 +281,14 @@ return false; Options.AC = &getAnalysis().getAssumptionCache(F); + if (F.hasFnAttribute(Attribute::OptForFuzzing)) { + Options.setSimplifyCondBranch(false) + .setFoldTwoEntryPHINode(false); + } else { + Options.setSimplifyCondBranch(true) + .setFoldTwoEntryPHINode(true); + } + auto &TTI = getAnalysis().getTTI(F); return simplifyFunctionCFG(F, TTI, Options); } Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2336,9 +2336,6 @@ // dependence information for this check, but simplifycfg can't keep it up // to date, and this catches most of the cases we care about anyway. BasicBlock *BB = PN->getParent(); - const Function *Fn = BB->getParent(); - if (Fn && Fn->hasFnAttribute(Attribute::OptForFuzzing)) - return false; BasicBlock *IfTrue, *IfFalse; Value *IfCond = GetIfCondition(BB, IfTrue, IfFalse); @@ -5969,8 +5966,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) { BasicBlock *BB = BI->getParent(); - const Function *Fn = BB->getParent(); - if (Fn && Fn->hasFnAttribute(Attribute::OptForFuzzing)) + if (!Options.SimplifyCondBranch) return false; // Conditional branch @@ -6184,11 +6180,13 @@ IRBuilder<> Builder(BB); - // If there is a trivial two-entry PHI node in this basic block, and we can - // eliminate it, do so now. - if (auto *PN = dyn_cast(BB->begin())) - if (PN->getNumIncomingValues() == 2) - Changed |= FoldTwoEntryPHINode(PN, TTI, DL); + if (Options.FoldTwoEntryPHINode) { + // If there is a trivial two-entry PHI node in this basic block, and we can + // eliminate it, do so now. + if (auto *PN = dyn_cast(BB->begin())) + if (PN->getNumIncomingValues() == 2) + Changed |= FoldTwoEntryPHINode(PN, TTI, DL); + } Instruction *Terminator = BB->getTerminator(); Builder.SetInsertPoint(Terminator);