File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1818
1919#include " swift/SILOptimizer/PassManager/Transforms.h"
2020#include " swift/SILOptimizer/Analysis/AliasAnalysis.h"
21+ #include " swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
2122#include " swift/SIL/NodeBits.h"
2223#include " swift/SIL/SILFunction.h"
2324#include " swift/SIL/SILBasicBlock.h"
@@ -176,6 +177,13 @@ void TempLValueOptPass::tempLValueOpt(CopyAddrInst *copyInst) {
176177 // but a block argument.
177178 SILInstruction *destRootInst = destRootAddr->getDefiningInstruction ();
178179
180+ bool needDestroyEarly = false ;
181+ BasicCalleeAnalysis *bca = nullptr ;
182+ if (!copyInst->isInitializationOfDest ()) {
183+ needDestroyEarly = true ;
184+ bca = PM->getAnalysis <BasicCalleeAnalysis>();
185+ }
186+
179187 // Iterate over the liferange of the temporary and make some validity checks.
180188 AliasAnalysis *AA = nullptr ;
181189 SILInstruction *beginOfLiferange = nullptr ;
@@ -220,6 +228,9 @@ void TempLValueOptPass::tempLValueOpt(CopyAddrInst *copyInst) {
220228 // Needed to treat init_existential_addr as not-writing projection.
221229 projections.contains (inst) == 0 )
222230 return ;
231+
232+ if (needDestroyEarly && isDeinitBarrier (inst, bca))
233+ return ;
223234 }
224235 }
225236 assert (endOfLiferangeReached);
Original file line number Diff line number Diff line change 11// RUN: %target-sil-opt -enable-sil-verify-all %s -temp-lvalue-opt | %FileCheck %s
22
3+ // REQUIRES: swift_in_compiler
4+
35import Swift
46import Builtin
57
@@ -300,3 +302,35 @@ bb0(%0 : $*T):
300302 return %78 : $()
301303}
302304
305+ sil @createAny : $@convention(thin) () -> @out Any
306+ sil @createAny_no_barrier : $@convention(thin) () -> @out Any {
307+ [global:]
308+ }
309+
310+ // CHECK-LABEL: sil [ossa] @test_deinit_barrier :
311+ // CHECK: copy_addr [take]
312+ // CHECK-LABEL: } // end sil function 'test_deinit_barrier'
313+ sil [ossa] @test_deinit_barrier : $@convention(thin) (@guaranteed Any, @inout Any) -> () {
314+ bb0(%0 : @guaranteed $Any, %1 : $*Any):
315+ %2 = alloc_stack $Any
316+ %4 = function_ref @createAny : $@convention(thin) () -> @out Any
317+ %5 = apply %4(%2) : $@convention(thin) () -> @out Any
318+ copy_addr [take] %2 to %1 : $*Any
319+ dealloc_stack %2 : $*Any
320+ %11 = tuple ()
321+ return %11 : $()
322+ }
323+
324+ // CHECK-LABEL: sil [ossa] @test_no_deinit_barrier :
325+ // CHECK-NOT: copy_addr
326+ // CHECK-LABEL: } // end sil function 'test_no_deinit_barrier'
327+ sil [ossa] @test_no_deinit_barrier : $@convention(thin) (@guaranteed Any, @inout Any) -> () {
328+ bb0(%0 : @guaranteed $Any, %1 : $*Any):
329+ %2 = alloc_stack $Any
330+ %4 = function_ref @createAny_no_barrier : $@convention(thin) () -> @out Any
331+ %5 = apply %4(%2) : $@convention(thin) () -> @out Any
332+ copy_addr [take] %2 to %1 : $*Any
333+ dealloc_stack %2 : $*Any
334+ %11 = tuple ()
335+ return %11 : $()
336+ }
You can’t perform that action at this time.
0 commit comments