Skip to content

Commit 05c7d64

Browse files
committed
We don't consider it profitable to jump thread when we could optimize arc in OSSA.
Copy propagation should be able to handle such cases without jump threading.
1 parent e3a98e8 commit 05c7d64

File tree

2 files changed

+5
-49
lines changed

2 files changed

+5
-49
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -944,14 +944,13 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
944944
for (unsigned i : indices(BI->getArgs())) {
945945
SILValue Arg = BI->getArg(i);
946946

947-
// TODO: Verify if we need to jump thread to remove releases in OSSA.
948947
// If the value being substituted on is release there is a chance we could
949948
// remove the release after jump threading.
950-
if (!Arg->getType().isTrivial(*SrcBB->getParent()) &&
951-
couldRemoveRelease(SrcBB, Arg, DestBB,
952-
DestBB->getArgument(i))) {
953-
ThreadingBudget = 8;
954-
break;
949+
// In ossa, copy propagation can do this, avoid jump threading.
950+
if (!Fn.hasOwnership() && !Arg->getType().isTrivial(*SrcBB->getParent()) &&
951+
couldRemoveRelease(SrcBB, Arg, DestBB, DestBB->getArgument(i))) {
952+
ThreadingBudget = 8;
953+
break;
955954
}
956955

957956
// If the value being substituted is an enum, check to see if there are any

test/SILOptimizer/simplify_cfg_ossa_disabled.sil

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,46 +1198,3 @@ bb3(%4 : @guaranteed $Optional<Klass>):
11981198
end_borrow %0a : $Klass
11991199
return %5a : $Klass
12001200
}
1201-
1202-
// CHECK-LABEL: sil [ossa] @jump_thread_retain_release :
1203-
// CHECK: cond_br
1204-
// CHECK: cond_br %3, bb4, bb3
1205-
//
1206-
// CHECK: bb3:
1207-
// CHECK: %3 = copy_value %2 : $Klass
1208-
// CHECK: destroy_value %2 : $Klass
1209-
// CHECK: br bb5(%3 : $Klass)
1210-
//
1211-
// CHECK: bb4:
1212-
// CHECK: %4 = copy_value %1 : $Klass
1213-
// CHECK: destroy_value %1 : $Klass
1214-
// CHECK: br bb5(%4 : $Klass)
1215-
// CHECK: } // end sil function 'jump_thread_retain_release'
1216-
sil [ossa] @jump_thread_retain_release : $@convention(thin) (Builtin.Int1, @owned Klass, @owned Klass, Builtin.Int1) -> () {
1217-
bb0(%0 : $Builtin.Int1, %1 : @owned $Klass, %2 : @owned $Klass, %3 : $Builtin.Int1):
1218-
cond_br %0, bb2, bb1
1219-
1220-
bb1:
1221-
br bb6(%2 : $Klass)
1222-
1223-
bb2:
1224-
cond_br %3, bb3, bb4
1225-
1226-
bb3:
1227-
%1a = copy_value %1 : $Klass
1228-
br bb5(%1a : $Klass)
1229-
1230-
bb4:
1231-
%2a = copy_value %2 : $Klass
1232-
br bb5(%2a : $Klass)
1233-
1234-
bb5(%11 : @owned $Klass):
1235-
destroy_value %2 : $Klass
1236-
br bb6(%11 : $Klass)
1237-
1238-
bb6(%14 : @owned $Klass):
1239-
destroy_value %14 : $Klass
1240-
destroy_value %1 : $Klass
1241-
%16 = tuple ()
1242-
return %16 : $()
1243-
}

0 commit comments

Comments
 (0)