Skip to content

Commit 900d8c3

Browse files
committed
Add ossa unit tests for SimplifyCFG::simplifyTermWithIdenticalDestBlocks
1 parent 73cd7a9 commit 900d8c3

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
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
@@ -472,6 +485,9 @@ void UnitTestRunner::withTest(StringRef name, Doit doit) {
472485
ADD_UNIT_TEST_SUBCLASS(
473486
"simplify-cfg-simplify-switch-enum-unreachable-blocks",
474487
SimplifyCFGSimplifySwitchEnumUnreachableBlocks)
488+
ADD_UNIT_TEST_SUBCLASS(
489+
"simplify-cfg-simplify-term-with-identical-dest-blocks",
490+
SimplifyCFGSimplifyTermWithIdenticalDestBlocks)
475491

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

test/SILOptimizer/simplify_cfg_ossa_simplify_branch.sil

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all %s -simplify-cfg
1+
// RUN: %target-sil-opt -unit-test-runner %s 2>&1 | %FileCheck %s
22

33
enum FakeOptional<T> {
44
case some(T)
@@ -45,3 +45,49 @@ 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+
// CHECK-LABEL: sil [ossa] @test_simplify_term_with_identical_dest_blocks1 :
55+
// CHECK: bb0
56+
// CHECK: br bb2
57+
// CHECK: bb1
58+
// CHECK-LABEL: } // end sil function 'test_simplify_term_with_identical_dest_blocks1'
59+
sil [ossa] @test_simplify_term_with_identical_dest_blocks1 : $@convention(thin) (@owned Klass) -> () {
60+
bb0(%0 : @owned $Klass):
61+
test_specification "simplify-cfg-simplify-term-with-identical-dest-blocks @block[0]"
62+
%1 = begin_borrow %0 : $Klass
63+
br bb1(%1 : $Klass)
64+
65+
bb1(%3 : @guaranteed $Klass):
66+
br bb2(%3 : $Klass)
67+
68+
bb2(%5 : @guaranteed $Klass):
69+
end_borrow %5 : $Klass
70+
destroy_value %0 : $Klass
71+
%t = tuple ()
72+
return %t : $()
73+
}
74+
75+
// CHECK-LABEL: sil [ossa] @test_simplify_term_with_identical_dest_blocks2 :
76+
// CHECK: bb0
77+
// CHECK: br bb2
78+
// CHECK: bb2
79+
// CHECK-LABEL: } // end sil function 'test_simplify_term_with_identical_dest_blocks2'
80+
sil [ossa] @test_simplify_term_with_identical_dest_blocks2 : $@convention(thin) (@owned Klass) -> () {
81+
bb0(%0 : @owned $Klass):
82+
test_specification "simplify-cfg-simplify-term-with-identical-dest-blocks @block[0]"
83+
br bb1(%0 : $Klass)
84+
85+
bb1(%3 : @owned $Klass):
86+
br bb2(%3 : $Klass)
87+
88+
bb2(%5 : @owned $Klass):
89+
destroy_value %5 : $Klass
90+
%t = tuple ()
91+
return %t : $()
92+
}
93+

0 commit comments

Comments
 (0)