Skip to content

Commit 0c2588e

Browse files
committed
Enable SimplifyCFG::simplifyTermWithIdenticalDestBlocks for OSSA
1 parent 6659491 commit 0c2588e

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,15 +2535,6 @@ bool SimplifyCFG::simplifyTermWithIdenticalDestBlocks(SILBasicBlock *BB) {
25352535
return false;
25362536
}
25372537
TermInst *Term = BB->getTerminator();
2538-
// TODO: OSSA; cleanup nontrivial terminator operands (if this ever actually
2539-
// happens)
2540-
if (!EnableOSSARewriteTerminator && Fn.hasOwnership()) {
2541-
if (llvm::any_of(Term->getOperandValues(), [this](SILValue op) {
2542-
return !op->getType().isTrivial(Fn);
2543-
})) {
2544-
return false;
2545-
}
2546-
}
25472538
LLVM_DEBUG(llvm::dbgs() << "replace term with identical dests: " << *Term);
25482539
SILBuilderWithScope(Term).createBranch(Term->getLoc(), commonDest.destBB,
25492540
commonDest.newSourceBranchArgs);

lib/SILOptimizer/UtilityPasses/UnitTestRunner.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,19 @@ struct SimplifyCFGSimplifySwitchEnumUnreachableBlocks : UnitTest {
309309
}
310310
};
311311

312+
struct SimplifyCFGSimplifyTermWithIdenticalDestBlocks : UnitTest {
313+
SimplifyCFGSimplifyTermWithIdenticalDestBlocks(UnitTestRunner *pass)
314+
: UnitTest(pass) {}
315+
void invoke(Arguments &arguments) override {
316+
auto *passToRun = cast<SILFunctionTransform>(createSimplifyCFG());
317+
passToRun->injectPassManager(getPass()->getPassManager());
318+
passToRun->injectFunction(getFunction());
319+
SimplifyCFG(*getFunction(), *passToRun, /*VerifyAll=*/false,
320+
/*EnableJumpThread=*/false)
321+
.simplifyTermWithIdenticalDestBlocks(arguments.takeBlock());
322+
}
323+
};
324+
312325
// Arguments:
313326
// - string: list of characters, each of which specifies subsequent arguments
314327
// - A: (block) argument
@@ -438,6 +451,9 @@ void UnitTestRunner::withTest(StringRef name, Doit doit) {
438451
ADD_UNIT_TEST_SUBCLASS(
439452
"simplify-cfg-simplify-switch-enum-unreachable-blocks",
440453
SimplifyCFGSimplifySwitchEnumUnreachableBlocks)
454+
ADD_UNIT_TEST_SUBCLASS(
455+
"simplify-cfg-simplify-term-with-identical-dest-blocks",
456+
SimplifyCFGSimplifyTermWithIdenticalDestBlocks)
441457

442458
ADD_UNIT_TEST_SUBCLASS("test-specification-parsing", TestSpecificationTest)
443459
ADD_UNIT_TEST_SUBCLASS("visit-adjacent-reborrows-of-phi", VisitAdjacentReborrowsOfPhiTest)

test/SILOptimizer/simplify_cfg_ossa_simplify_branch.sil

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,39 @@ bb6:
4545
inject_enum_addr %0 : $*FakeOptional<Klass>, #FakeOptional.none!enumelt
4646
br bb5
4747
}
48+
49+
enum E1<T> {
50+
case some1(T)
51+
case some2(T)
52+
}
53+
54+
sil [ossa] @test_simplify_term_with_identical_dest_blocks1 : $@convention(thin) (@owned Klass) -> () {
55+
bb0(%0 : @owned $Klass):
56+
test_specification "simplify-cfg-simplify-term-with-identical-dest-blocks @block[0]"
57+
%1 = begin_borrow %0 : $Klass
58+
br bb1(%1 : $Klass)
59+
60+
bb1(%3 : @guaranteed $Klass):
61+
br bb2(%3 : $Klass)
62+
63+
bb2(%5 : @guaranteed $Klass):
64+
end_borrow %5 : $Klass
65+
destroy_value %0 : $Klass
66+
%t = tuple ()
67+
return %t : $()
68+
}
69+
70+
sil [ossa] @test_simplify_term_with_identical_dest_blocks2 : $@convention(thin) (@owned Klass) -> () {
71+
bb0(%0 : @owned $Klass):
72+
test_specification "simplify-cfg-simplify-term-with-identical-dest-blocks @block[0]"
73+
br bb1(%0 : $Klass)
74+
75+
bb1(%3 : @owned $Klass):
76+
br bb2(%3 : $Klass)
77+
78+
bb2(%5 : @owned $Klass):
79+
destroy_value %5 : $Klass
80+
%t = tuple ()
81+
return %t : $()
82+
}
83+

0 commit comments

Comments
 (0)