Skip to content

[Mem2Reg] Always bail on dynamic_lifetime. #76656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/SILOptimizer/Transforms/SILMem2Reg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2185,8 +2185,7 @@ bool MemoryToRegisters::promoteAllocation(AllocStackInst *alloc,
++NumAllocStackFound;

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

Expand Down
18 changes: 18 additions & 0 deletions test/SILOptimizer/mem2reg.sil
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,21 @@ bb0:
dealloc_stack %11 : $*Pair<T, ()>
return undef : $()
}

// CHECK-LABEL: sil @dont_promote_dynamic_lifetime : {{.*}} {
// CHECK: alloc_stack
// CHECK-LABEL: } // end sil function 'dont_promote_dynamic_lifetime'
sil @dont_promote_dynamic_lifetime : $@convention(thin) () -> () {
%stack = alloc_stack [dynamic_lifetime] $Klass
cond_br undef, left, right
left:
%kin = apply undef() : $@convention(thin) () -> (@owned Klass)
%k = load %stack : $*Klass
strong_release %k : $Klass
br exit
right:
br exit
exit:
dealloc_stack %stack : $*Klass
return undef : $()
}