diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp index 4e437e9abeb43..74e4dd2bd991a 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -85,6 +85,10 @@ static cl::opt UserSpeculateUnpredictables( "speculate-unpredictables", cl::Hidden, cl::init(false), cl::desc("Speculate unpredictable branches (default = false)")); +static cl::opt DisableSimplifyCFG( + "disable-simplify-cfg", cl::Hidden, cl::init(false), + cl::desc("Disable simplify cfg")); + STATISTIC(NumSimpl, "Number of blocks simplified"); static bool @@ -307,6 +311,9 @@ static bool simplifyFunctionCFG(Function &F, const TargetTransformInfo &TTI, (DT && DT->verify(DominatorTree::VerificationLevel::Full))) && "Original domtree is invalid?"); + if (DisableSimplifyCFG) + return false; + bool Changed = simplifyFunctionCFGImpl(F, TTI, DT, Options); assert((!RequireAndPreserveDomTree || diff --git a/llvm/test/Transforms/SimplifyCFG/disable-simplify-cfg.ll b/llvm/test/Transforms/SimplifyCFG/disable-simplify-cfg.ll new file mode 100644 index 0000000000000..f5cef9314e283 --- /dev/null +++ b/llvm/test/Transforms/SimplifyCFG/disable-simplify-cfg.ll @@ -0,0 +1,13 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt < %s -passes=simplifycfg -disable-simplify-cfg=true -S | FileCheck %s + +define void @test1() { +; CHECK-LABEL: define void @test1() { +; CHECK-NEXT: br label %[[BB1:.*]] +; CHECK: [[BB1]]: +; CHECK-NEXT: ret void +; + br label %1 + ret void +} +