Skip to content

Commit 7c20f2d

Browse files
author
git apple-llvm automerger
committed
Merge commit '7c5f104e4549' from llvm.org/main into next
2 parents 717010b + 7c5f104 commit 7c20f2d

File tree

4 files changed

+21
-92
lines changed

4 files changed

+21
-92
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ static cl::opt<unsigned> TwoEntryPHINodeFoldingThreshold(
113113
"to speculatively execute to fold a 2-entry PHI node into a "
114114
"select (default = 4)"));
115115

116-
static cl::opt<bool> DupRet(
117-
"simplifycfg-dup-ret", cl::Hidden, cl::init(false),
118-
cl::desc("Duplicate return instructions into unconditional branches"));
119-
120116
static cl::opt<bool>
121117
HoistCommon("simplifycfg-hoist-common", cl::Hidden, cl::init(true),
122118
cl::desc("Hoist common instructions up to the parent block"));
@@ -4638,32 +4634,12 @@ bool SimplifyCFGOpt::simplifyReturn(ReturnInst *RI, IRBuilder<> &Builder) {
46384634
return false;
46394635

46404636
// Find predecessors that end with branches.
4641-
SmallVector<BasicBlock *, 8> UncondBranchPreds;
46424637
SmallVector<BranchInst *, 8> CondBranchPreds;
46434638
for (BasicBlock *P : predecessors(BB)) {
46444639
Instruction *PTI = P->getTerminator();
4645-
if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) {
4646-
if (BI->isUnconditional())
4647-
UncondBranchPreds.push_back(P);
4648-
else
4640+
if (BranchInst *BI = dyn_cast<BranchInst>(PTI))
4641+
if (BI->isConditional())
46494642
CondBranchPreds.push_back(BI);
4650-
}
4651-
}
4652-
4653-
// If we found some, do the transformation!
4654-
if (!UncondBranchPreds.empty() && DupRet) {
4655-
while (!UncondBranchPreds.empty()) {
4656-
BasicBlock *Pred = UncondBranchPreds.pop_back_val();
4657-
LLVM_DEBUG(dbgs() << "FOLDING: " << *BB
4658-
<< "INTO UNCOND BRANCH PRED: " << *Pred);
4659-
(void)FoldReturnIntoUncondBranch(RI, BB, Pred, DTU);
4660-
}
4661-
4662-
// If we eliminated all predecessors of the block, delete the block now.
4663-
if (pred_empty(BB))
4664-
DeleteDeadBlock(BB, DTU);
4665-
4666-
return true;
46674643
}
46684644

46694645
// Check out all of the conditional branches going to this return

llvm/test/Transforms/SimplifyCFG/duplicate-ret-into-uncond-br.ll

Lines changed: 0 additions & 31 deletions
This file was deleted.

llvm/test/Transforms/SimplifyCFG/merge-duplicate-conditional-ret-val.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
2-
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -simplifycfg-dup-ret -S | FileCheck %s
2+
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
33

44
declare void @bar()
55
declare void @baz()

llvm/test/Transforms/SimplifyCFG/return-merge.ll

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck --check-prefixes=CHECK,NODUPRET %s
3-
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -simplifycfg-dup-ret -S | FileCheck --check-prefixes=CHECK,DUPRET %s
2+
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck --check-prefixes=CHECK %s
43
; RUN: opt < %s -debugify -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck --check-prefixes=DBGINFO %s
54

65
define i32 @test1(i1 %C) {
@@ -24,12 +23,9 @@ F: ; preds = %entry
2423
}
2524

2625
define void @test2(i1 %C) {
27-
; NODUPRET-LABEL: @test2(
28-
; NODUPRET-NEXT: common.ret:
29-
; NODUPRET-NEXT: ret void
30-
;
31-
; DUPRET-LABEL: @test2(
32-
; DUPRET-NEXT: ret void
26+
; CHECK-LABEL: @test2(
27+
; CHECK-NEXT: common.ret:
28+
; CHECK-NEXT: ret void
3329
;
3430
; DBGINFO-LABEL: @test2(
3531
; DBGINFO-NEXT: common.ret:
@@ -48,32 +44,20 @@ declare void @sideeffect1()
4844
declare void @sideeffect2()
4945

5046
define i32 @test3(i1 %C0, i1 %C1, i32 %v0, i32 %v1, i32 %v2) {
51-
; NODUPRET-LABEL: @test3(
52-
; NODUPRET-NEXT: entry:
53-
; NODUPRET-NEXT: call void @sideeffect0()
54-
; NODUPRET-NEXT: br i1 [[C0:%.*]], label [[T:%.*]], label [[F:%.*]]
55-
; NODUPRET: end:
56-
; NODUPRET-NEXT: [[R:%.*]] = phi i32 [ [[V2:%.*]], [[F]] ], [ [[SPEC_SELECT:%.*]], [[T]] ]
57-
; NODUPRET-NEXT: ret i32 [[R]]
58-
; NODUPRET: T:
59-
; NODUPRET-NEXT: call void @sideeffect1()
60-
; NODUPRET-NEXT: [[SPEC_SELECT]] = select i1 [[C1:%.*]], i32 [[V0:%.*]], i32 [[V1:%.*]]
61-
; NODUPRET-NEXT: br label [[END:%.*]]
62-
; NODUPRET: F:
63-
; NODUPRET-NEXT: call void @sideeffect2()
64-
; NODUPRET-NEXT: br label [[END]]
65-
;
66-
; DUPRET-LABEL: @test3(
67-
; DUPRET-NEXT: entry:
68-
; DUPRET-NEXT: call void @sideeffect0()
69-
; DUPRET-NEXT: br i1 [[C0:%.*]], label [[T:%.*]], label [[F:%.*]]
70-
; DUPRET: T:
71-
; DUPRET-NEXT: call void @sideeffect1()
72-
; DUPRET-NEXT: [[RETVAL:%.*]] = select i1 [[C1:%.*]], i32 [[V0:%.*]], i32 [[V1:%.*]]
73-
; DUPRET-NEXT: ret i32 [[RETVAL]]
74-
; DUPRET: F:
75-
; DUPRET-NEXT: call void @sideeffect2()
76-
; DUPRET-NEXT: ret i32 [[V2:%.*]]
47+
; CHECK-LABEL: @test3(
48+
; CHECK-NEXT: entry:
49+
; CHECK-NEXT: call void @sideeffect0()
50+
; CHECK-NEXT: br i1 [[C0:%.*]], label [[T:%.*]], label [[F:%.*]]
51+
; CHECK: end:
52+
; CHECK-NEXT: [[R:%.*]] = phi i32 [ [[V2:%.*]], [[F]] ], [ [[SPEC_SELECT:%.*]], [[T]] ]
53+
; CHECK-NEXT: ret i32 [[R]]
54+
; CHECK: T:
55+
; CHECK-NEXT: call void @sideeffect1()
56+
; CHECK-NEXT: [[SPEC_SELECT]] = select i1 [[C1:%.*]], i32 [[V0:%.*]], i32 [[V1:%.*]]
57+
; CHECK-NEXT: br label [[END:%.*]]
58+
; CHECK: F:
59+
; CHECK-NEXT: call void @sideeffect2()
60+
; CHECK-NEXT: br label [[END]]
7761
;
7862
; DBGINFO-LABEL: @test3(
7963
; DBGINFO-NEXT: entry:

0 commit comments

Comments
 (0)