From 664881c9ee2704e6b3a322b75409eefe686435b2 Mon Sep 17 00:00:00 2001 From: Madhur Amilkanthwar Date: Wed, 12 Mar 2025 00:40:17 -0700 Subject: [PATCH] [SimplifyCFG] Add command-line option to disable the pass The option is useful for some of the experiments we're doing. I don't see any harm in having such option and the ability to disable the pass. --- llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp | 7 +++++++ .../Transforms/SimplifyCFG/disable-simplify-cfg.ll | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 llvm/test/Transforms/SimplifyCFG/disable-simplify-cfg.ll 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 +} +