Skip to content

Commit 62c3850

Browse files
committed
TempRValueElimination: allow elimination of dead alloc_stacks in non-OSSA
1 parent 8618a39 commit 62c3850

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/TempRValueElimination.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ private func getRemovableAllocStackDestination(
160160
// %x = load %allocStack // looks like a load, but is a `load [take]`
161161
// strong_release %x
162162
// ```
163-
guard copy.parentFunction.hasOwnership || allocStack.isDestroyedOnAllPaths(context) else {
163+
guard copy.parentFunction.hasOwnership ||
164+
allocStack.isDestroyedOnAllPaths(context) ||
165+
// We can easily remove a dead alloc_stack
166+
allocStack.uses.ignore(user: copy).ignore(usersOfType: DeallocStackInst.self).isEmpty
167+
else {
164168
return nil
165169
}
166170

test/IRGen/existentials_opaque_boxed.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-type-layout %s -emit-ir | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-%target-ptrsize -DINT=i%target-ptrsize --check-prefix=CHECK-%target-cpu
1+
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=mandatory-temp-rvalue-elimination -disable-type-layout %s -emit-ir | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-%target-ptrsize -DINT=i%target-ptrsize --check-prefix=CHECK-%target-cpu
22

33
sil_stage canonical
44

test/IRGen/outlined_copy_addr.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
3-
// RUN: %target-swift-frontend -emit-ir %s -I %t | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-module -Xllvm -sil-disable-pass=mandatory-temp-rvalue-elimination -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
3+
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=mandatory-temp-rvalue-elimination -emit-ir %s -I %t | %FileCheck %s
44

55
import Swift
66
import resilient_struct

test/SILOptimizer/temp_rvalue_opt.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class C {
2929
@_hasStorage let x: String
3030
}
3131

32+
struct NC: ~Copyable {
33+
var i: Int
34+
}
3235

3336
sil @unknown : $@convention(thin) () -> ()
3437
sil @load_string : $@convention(thin) (@in_guaranteed String) -> String
@@ -842,3 +845,16 @@ bb0(%0 : $*Klass):
842845
return %4
843846
}
844847

848+
// CHECK-LABEL: sil @dead_alloc_stack :
849+
// CHECK: bb0(%0 : $*NC):
850+
// CHECK-NEXT: tuple
851+
// CHECK-LABEL: } // end sil function 'dead_alloc_stack'
852+
sil @dead_alloc_stack : $@convention(thin) (@in NC) -> () {
853+
bb0(%0 : $*NC):
854+
%1 = alloc_stack $NC
855+
copy_addr [take] %0 to [init] %1
856+
dealloc_stack %1
857+
%r = tuple ()
858+
return %r
859+
}
860+

0 commit comments

Comments
 (0)