Skip to content

Commit 224d36c

Browse files
committed
[DCE] Insts that define lexical values seem useful
Don't delete as dead instructions that define lexical values such as `move_value [lexical]`. rdar://129299803
1 parent 67c0fd8 commit 224d36c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ static bool seemsUseful(SILInstruction *I) {
6363
if (I->mayHaveSideEffects())
6464
return true;
6565

66+
if (llvm::any_of(I->getResults(),
67+
[](auto result) { return result->isLexical(); })) {
68+
return true;
69+
}
70+
6671
if (auto *BI = dyn_cast<BuiltinInst>(I)) {
6772
// Although the onFastPath builtin has no side-effects we don't want to
6873
// remove it.

test/SILOptimizer/dead_code_elimination_ossa.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ typealias Int1 = Builtin.Int1
1313

1414
class C {}
1515

16+
sil @getC : $@convention(thin) () -> @owned C
17+
sil @barrier : $@convention(thin) () -> ()
18+
1619
struct CAndBit {
1720
var c: C
1821
var bit: Int1
@@ -468,3 +471,20 @@ bb3:
468471
%22 = tuple ()
469472
return %22 : $()
470473
}
474+
475+
// CHECK-LABEL: sil [ossa] @dont_delete_move_value_lexical : {{.*}} {
476+
// CHECK: [[LEXICAL:%[^,]+]] = move_value [lexical]
477+
// CHECK: [[DUMMY:%[^,]+]] = function_ref @dummy
478+
// CHECK: apply [[DUMMY]]()
479+
// CHECK: destroy_value [[LEXICAL]]
480+
// CHECK-LABEL: } // end sil function 'dont_delete_move_value_lexical'
481+
sil [ossa] @dont_delete_move_value_lexical : $@convention(thin) () -> () {
482+
%getC = function_ref @getC : $@convention(thin) () -> @owned C
483+
%c = apply %getC() : $@convention(thin) () -> @owned C
484+
%m = move_value [lexical] %c : $C
485+
%dummy = function_ref @dummy : $@convention(thin) () -> ()
486+
apply %dummy() : $@convention(thin) () -> ()
487+
destroy_value %m : $C
488+
%retval = tuple ()
489+
return %retval : $()
490+
}

0 commit comments

Comments
 (0)