Skip to content

Commit e272564

Browse files
committed
[sil-opaque-values] Fix UpdateSSA to handle checked_cast_value_br.
1 parent 699996b commit e272564

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/SILOptimizer/Utils/CFG.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,14 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB,
550550
SuccBB->getArgument(0)->getType(), ValueOwnershipKind::Owned));
551551
return;
552552
}
553+
if (auto CBI = dyn_cast<CheckedCastValueBranchInst>(T)) {
554+
auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB() : CBI->getFailureBB();
555+
if (!SuccBB->getNumArguments())
556+
return;
557+
Args.push_back(NewEdgeBB->createPHIArgument(
558+
SuccBB->getArgument(0)->getType(), ValueOwnershipKind::Owned));
559+
return;
560+
}
553561

554562
if (auto *TAI = dyn_cast<TryApplyInst>(T)) {
555563
auto *SuccBB = EdgeIdx == 0 ? TAI->getNormalBB() : TAI->getErrorBB();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %target-sil-opt -enable-sil-opaque-values -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -simplify-cfg | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
protocol P {}
6+
7+
// Test jump threading into a destination block terminated by checked_cast_value_br.
8+
//
9+
// CHECK-LABEL: sil @testJumpThread : $@convention(thin) (Any, Any) -> () {
10+
// CHECK: bb0(%0 : $Any, %1 : $Any):
11+
// CHECK: cond_br undef, bb1, bb4
12+
// CHECK: bb1:
13+
// CHECK: retain_value %0 : $Any
14+
// CHECK: release_value %0 : $Any
15+
// CHECK: checked_cast_value_br %0 : $Any to $P, bb3, bb2
16+
// CHECK-LABEL: } // end sil function 'testJumpThread'
17+
sil @testJumpThread : $@convention(thin) (Any, Any) -> () {
18+
bb0(%0 : $Any, %1 : $Any):
19+
cond_br undef, bb1, bb2
20+
bb1:
21+
retain_value %0 : $Any // force jump-threading
22+
br bb6(%0 : $Any)
23+
bb2:
24+
br bb6(%1 : $Any)
25+
bb6(%any : $Any):
26+
release_value %any : $Any // force jump-threading
27+
checked_cast_value_br %any : $Any to $P, bb7, bb8
28+
bb7(%p : $P):
29+
br bb9
30+
bb8:
31+
br bb9
32+
bb9:
33+
%999 = tuple ()
34+
return %999 : $()
35+
}

0 commit comments

Comments
 (0)