Skip to content

Commit db6a36f

Browse files
committed
Enable SimplifyCFG::simplifyArgs in OSSA
1 parent cc6004e commit db6a36f

File tree

3 files changed

+128
-9
lines changed

3 files changed

+128
-9
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,15 +3866,6 @@ bool SimplifyCFG::simplifyArgs(SILBasicBlock *BB) {
38663866
if (BB->pred_empty())
38673867
return false;
38683868

3869-
if (!EnableOSSARewriteTerminator && Fn.hasOwnership()) {
3870-
// TODO: OSSA phi support
3871-
if (llvm::any_of(BB->getArguments(), [this](SILArgument *arg) {
3872-
return !arg->getType().isTrivial(Fn);
3873-
})) {
3874-
return false;
3875-
}
3876-
}
3877-
38783869
// Ignore blocks that are successors of terminators with mandatory args.
38793870
for (SILBasicBlock *pred : BB->getPredecessorBlocks()) {
38803871
if (hasMandatoryArgument(pred->getTerminator()))

lib/SILOptimizer/UtilityPasses/UnitTestRunner.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@ struct ShrinkBorrowScopeTest : UnitTest {
270270
}
271271
};
272272

273+
struct SimplifyCFGSimplifyBlockArgs : UnitTest {
274+
SimplifyCFGSimplifyBlockArgs(UnitTestRunner *pass)
275+
: UnitTest(pass) {}
276+
void invoke(Arguments &arguments) override {
277+
auto *passToRun = cast<SILFunctionTransform>(createSimplifyCFG());
278+
passToRun->injectPassManager(getPass()->getPassManager());
279+
passToRun->injectFunction(getFunction());
280+
SimplifyCFG(*getFunction(), *passToRun, /*VerifyAll=*/false,
281+
/*EnableJumpThread=*/false)
282+
.simplifyBlockArgs();
283+
}
284+
};
273285
struct SimplifyCFGCanonicalizeSwitchEnum : UnitTest {
274286
SimplifyCFGCanonicalizeSwitchEnum(UnitTestRunner *pass) : UnitTest(pass) {}
275287
void invoke(Arguments &arguments) override {
@@ -444,6 +456,8 @@ void UnitTestRunner::withTest(StringRef name, Doit doit) {
444456
ADD_UNIT_TEST_SUBCLASS("shrink-borrow-scope", ShrinkBorrowScopeTest)
445457

446458
// SimplifyCFG unit tests
459+
ADD_UNIT_TEST_SUBCLASS("simplify-cfg-simplify-block-args",
460+
SimplifyCFGSimplifyBlockArgs)
447461
ADD_UNIT_TEST_SUBCLASS("simplify-cfg-canonicalize-switch-enum",
448462
SimplifyCFGCanonicalizeSwitchEnum)
449463
ADD_UNIT_TEST_SUBCLASS("simplify-cfg-simplify-switch-enum-block",
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// RUN: %target-sil-opt -unit-test-runner %s 2>&1 | %FileCheck %s
2+
3+
class Klass {}
4+
5+
// CHECK-LABEL: sil [ossa] @test_simplify_args1 :
6+
// CHECK: bb2:
7+
// CHECK-LABEL: } // end sil function 'test_simplify_args1'
8+
sil [ossa] @test_simplify_args1 : $@convention(thin) (@owned Klass) -> () {
9+
bb0(%0 : @owned $Klass):
10+
test_specification "simplify-cfg-simplify-block-args"
11+
%1 = begin_borrow %0 : $Klass
12+
br bb1(%1 : $Klass)
13+
14+
bb1(%3 : @guaranteed $Klass):
15+
br bb2(%3 : $Klass)
16+
17+
bb2(%5 : @guaranteed $Klass):
18+
end_borrow %5 : $Klass
19+
destroy_value %0 : $Klass
20+
%t = tuple ()
21+
return %t : $()
22+
}
23+
24+
// CHECK-LABEL: sil [ossa] @test_simplify_args2 :
25+
// CHECK: bb3({{.*}}):
26+
// CHECK-LABEL: } // end sil function 'test_simplify_args2'
27+
sil [ossa] @test_simplify_args2 : $@convention(thin) (@owned Klass, @owned Klass) -> () {
28+
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
29+
test_specification "simplify-cfg-simplify-block-args"
30+
cond_br undef, bb1, bb2
31+
32+
bb1:
33+
%2 = begin_borrow %0 : $Klass
34+
br bb3(%2 : $Klass)
35+
36+
bb2:
37+
%3 = begin_borrow %1 : $Klass
38+
br bb3(%3 : $Klass)
39+
40+
bb3(%4 : @guaranteed $Klass):
41+
end_borrow %4 : $Klass
42+
destroy_value %0 : $Klass
43+
destroy_value %1 : $Klass
44+
%t = tuple ()
45+
return %t : $()
46+
}
47+
48+
// CHECK-LABEL: sil [ossa] @test_simplify_args3 :
49+
// CHECK: bb3({{.*}}):
50+
// CHECK-LABEL: } // end sil function 'test_simplify_args3'
51+
sil [ossa] @test_simplify_args3 : $@convention(thin) (@owned Klass, @owned Klass) -> () {
52+
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
53+
test_specification "simplify-cfg-simplify-block-args"
54+
cond_br undef, bb1, bb2
55+
56+
bb1:
57+
destroy_value %0 : $Klass
58+
br bb3(%1 : $Klass)
59+
60+
bb2:
61+
destroy_value %1 : $Klass
62+
br bb3(%0 : $Klass)
63+
64+
bb3(%4 : @owned $Klass):
65+
destroy_value %4 : $Klass
66+
%t = tuple ()
67+
return %t : $()
68+
}
69+
70+
// CHECK-LABEL: sil [ossa] @test_simplify_args4 :
71+
// CHECK: bb3:
72+
// CHECK-LABEL: } // end sil function 'test_simplify_args4'
73+
sil [ossa] @test_simplify_args4 : $@convention(thin) (@owned Klass, @owned Klass) -> () {
74+
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
75+
test_specification "simplify-cfg-simplify-block-args"
76+
cond_br undef, bb1, bb2
77+
78+
bb1:
79+
destroy_value %0 : $Klass
80+
br bb3(%1 : $Klass)
81+
82+
bb2:
83+
destroy_value %0 : $Klass
84+
br bb3(%1 : $Klass)
85+
86+
bb3(%4 : @owned $Klass):
87+
destroy_value %4 : $Klass
88+
%t = tuple ()
89+
return %t : $()
90+
}
91+
92+
// CHECK-LABEL: sil [ossa] @test_simplify_args5 :
93+
// CHECK: bb3:
94+
// CHECK-LABEL: } // end sil function 'test_simplify_args5'
95+
sil [ossa] @test_simplify_args5 : $@convention(thin) (@owned Klass, @owned Klass) -> () {
96+
bb0(%0 : @owned $Klass, %1 : @owned $Klass):
97+
test_specification "simplify-cfg-simplify-block-args"
98+
%2 = begin_borrow %0 : $Klass
99+
cond_br undef, bb1, bb2
100+
101+
bb1:
102+
br bb3(%2 : $Klass)
103+
104+
bb2:
105+
br bb3(%2 : $Klass)
106+
107+
bb3(%4 : @guaranteed $Klass):
108+
end_borrow %4 : $Klass
109+
destroy_value %0 : $Klass
110+
destroy_value %1 : $Klass
111+
%t = tuple ()
112+
return %t : $()
113+
}
114+

0 commit comments

Comments
 (0)