Skip to content

Commit b9228c8

Browse files
Merge pull request #76656 from nate-chandler/rdar136388508
[Mem2Reg] Always bail on dynamic_lifetime.
2 parents 6fb2989 + c420b0e commit b9228c8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2185,8 +2185,7 @@ bool MemoryToRegisters::promoteAllocation(AllocStackInst *alloc,
21852185
++NumAllocStackFound;
21862186

21872187
// In OSSA, don't do Mem2Reg on non-trivial alloc_stack with dynamic_lifetime.
2188-
if (alloc->hasDynamicLifetime() && f.hasOwnership() &&
2189-
!alloc->getType().isTrivial(f)) {
2188+
if (alloc->hasDynamicLifetime() && !alloc->getType().isTrivial(f)) {
21902189
return false;
21912190
}
21922191

test/SILOptimizer/mem2reg.sil

+18
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,21 @@ bb0:
578578
dealloc_stack %11 : $*Pair<T, ()>
579579
return undef : $()
580580
}
581+
582+
// CHECK-LABEL: sil @dont_promote_dynamic_lifetime : {{.*}} {
583+
// CHECK: alloc_stack
584+
// CHECK-LABEL: } // end sil function 'dont_promote_dynamic_lifetime'
585+
sil @dont_promote_dynamic_lifetime : $@convention(thin) () -> () {
586+
%stack = alloc_stack [dynamic_lifetime] $Klass
587+
cond_br undef, left, right
588+
left:
589+
%kin = apply undef() : $@convention(thin) () -> (@owned Klass)
590+
%k = load %stack : $*Klass
591+
strong_release %k : $Klass
592+
br exit
593+
right:
594+
br exit
595+
exit:
596+
dealloc_stack %stack : $*Klass
597+
return undef : $()
598+
}

0 commit comments

Comments
 (0)