Skip to content

Commit c5ab128

Browse files
committed
Preserve extend_lifetime during dead instruction code elimination.
1 parent fad765b commit c5ab128

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ extension Instruction {
308308
// Don't remove UncheckedEnumDataInst in OSSA in case it is responsible
309309
// for consuming an enum value.
310310
return !parentFunction.hasOwnership
311+
case is ExtendLifetimeInst:
312+
// An extend_lifetime can only be removed if the operand is also removed.
313+
// If its operand is trivial, it will be removed by MandatorySimplification.
314+
return false
311315
default:
312316
break
313317
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification | %FileCheck %s
2+
3+
// REQUIRES: swift_in_compiler
4+
5+
sil_stage raw
6+
7+
import Builtin
8+
import Swift
9+
import SwiftShims
10+
11+
// extend_lifetime should not be eliminated as dead code.
12+
//
13+
// CHECK-LABEL: sil [ossa] @do_not_remove_extend : $@convention(thin) (Int) -> () {
14+
// CHECK: extend_lifetime %0 : $Int
15+
// CHECK-LABEL: } // end sil function 'do_not_remove_extend'
16+
sil [ossa] @do_not_remove_extend : $@convention(thin) (Int) -> () {
17+
bb0(%0 : $Int):
18+
extend_lifetime %0 : $Int
19+
%4 = tuple ()
20+
return %4 : $()
21+
}

0 commit comments

Comments
 (0)