Skip to content

Commit da0f1ed

Browse files
committed
Fix CopyPropagation: remove broken critical edge handling.
1 parent 34c48f1 commit da0f1ed

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,10 @@ static bool computeLiveness(CopyPropagationState &pass) {
453453
/// (assuming no critical edges).
454454
static void insertDestroyOnCFGEdge(SILBasicBlock *predBB, SILBasicBlock *succBB,
455455
CopyPropagationState &pass) {
456-
// FIXME: ban critical edges and avoid invalidating CFG analyses.
457-
auto *destroyBB = splitIfCriticalEdge(predBB, succBB);
458-
if (destroyBB != succBB)
459-
pass.markInvalid(SILAnalysis::InvalidationKind::Branches);
456+
assert(succBB->getSinglePredecessorBlock() == predBB &&
457+
"value is live-out on another predBB successor: critical edge?");
460458

461-
SILBuilderWithScope builder(destroyBB->begin());
459+
SILBuilderWithScope builder(succBB->begin());
462460
auto *di =
463461
builder.createDestroyValue(succBB->begin()->getLoc(), pass.currDef);
464462

@@ -543,13 +541,8 @@ static void findOrInsertDestroys(CopyPropagationState &pass) {
543541
auto visitBB = [&](SILBasicBlock *bb, SILBasicBlock *succBB) {
544542
switch (pass.liveness.isBlockLive(bb)) {
545543
case LiveOut:
546-
// If succBB is null, then the original destroy must be an inner
547-
// nested destroy, so just skip it.
548-
//
549-
// Otherwise, this CFG edge is a liveness boundary, so insert a new
550-
// destroy on the edge.
551-
if (succBB)
552-
insertDestroyOnCFGEdge(bb, succBB, pass);
544+
assert(succBB && "value live-out of a block where it is consumed");
545+
insertDestroyOnCFGEdge(bb, succBB, pass);
553546
break;
554547
case LiveWithin:
555548
// The liveness boundary is inside this block. Insert a final destroy

test/SILOptimizer/copy_propagation.sil

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,18 @@ bb0(%arg : @owned $T, %addr : $*T):
166166
// CHECK-LABEL: } // end sil function 'testDestroyEdge'
167167
sil [ossa] @testDestroyEdge : $@convention(thin) <T> (@in T, @inout T, Builtin.Int1) -> () {
168168
bb0(%arg : @owned $T, %addr : $*T, %z : $Builtin.Int1):
169-
cond_br %z, bb1, bb2
169+
cond_br %z, bb2, bb1
170170

171171
bb1:
172+
br bb3
173+
174+
bb2:
172175
debug_value %arg : $T
173176
%copy = copy_value %arg : $T
174177
destroy_value %copy : $T
175-
br bb2
178+
br bb3
176179

177-
bb2:
180+
bb3:
178181
destroy_value %arg : $T
179182
%10 = tuple ()
180183
return %10 : $()

0 commit comments

Comments
 (0)