Skip to content

Commit 3432037

Browse files
committed
Add cmdline option to apply more aggressive cfg merging
1 parent d912e14 commit 3432037

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ static cl::opt<unsigned> MaxSwitchCasesPerResult(
198198
"max-switch-cases-per-result", cl::Hidden, cl::init(16),
199199
cl::desc("Limit cases to analyze when converting a switch to select"));
200200

201+
static cl::opt<bool> MergeBlockIntoPredecessorWithTwoSuccessor(
202+
"simplifycfg-merge-into-pred-with-two-succ", cl::Hidden, cl::init(false),
203+
cl::desc("Allow SimplifyCFG to merge blocks into predecessor even when the predecessor has two successors"));
204+
201205
STATISTIC(NumBitMaps, "Number of switch instructions turned into bitmaps");
202206
STATISTIC(NumLinearMaps,
203207
"Number of switch instructions turned into linear mapping");
@@ -8339,7 +8343,7 @@ bool SimplifyCFGOpt::simplifyOnce(BasicBlock *BB) {
83398343
// Merge basic blocks into their predecessor if there is only one distinct
83408344
// pred, and if there is only one distinct successor of the predecessor, and
83418345
// if there are no PHI nodes.
8342-
if (MergeBlockIntoPredecessor(BB, DTU))
8346+
if (MergeBlockIntoPredecessor(BB, DTU, nullptr, nullptr, nullptr, MergeBlockIntoPredecessorWithTwoSuccessor))
83438347
return true;
83448348

83458349
if (SinkCommon && Options.SinkCommonInsts)

llvm/test/Transforms/SimplifyCFG/two-succ-merge-block.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --tool ./opt --version 5
2-
; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s
2+
; RUN: opt < %s -passes=simplifycfg -simplifycfg-merge-into-pred-with-two-succ -S | FileCheck %s
33

44
define i1 @_Z7compareRK1SS1_(ptr %a, ptr %b) {
55
; CHECK-LABEL: @_Z7compareRK1SS1_(

0 commit comments

Comments
 (0)