Skip to content

Commit e9279e2

Browse files
Merge pull request #75292 from nate-chandler/rdar131882748
[Mem2Reg] Bail on address-only types.
2 parents e2a0be8 + 1b9567b commit e9279e2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,12 @@ bool MemoryToRegisters::promoteAllocation(AllocStackInst *alloc,
22032203
return true;
22042204
}
22052205

2206+
// The value stored into an alloc_stack whose type address-only can never be
2207+
// represented in a register. Bail out.
2208+
if (alloc->getType().isAddressOnly(f)) {
2209+
return false;
2210+
}
2211+
22062212
// For AllocStacks that are only used within a single basic blocks, use
22072213
// the linear sweep to remove the AllocStack.
22082214
if (inSingleBlock) {

test/SILOptimizer/mem2reg.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import Builtin
44
import Swift
5+
import _Concurrency
56

67
//////////////////
78
// Declarations //
@@ -547,3 +548,33 @@ bb0:
547548
dealloc_stack %11 : $*(Builtin.BridgeObject, ())
548549
return undef : $()
549550
}
551+
552+
typealias ResilientTy = CheckedContinuation<(), Error>
553+
554+
// CHECK-LABEL: sil @dont_promote_addronly_aggregate : {{.*}} {
555+
// CHECK: alloc_stack
556+
// CHECK-LABEL: } // end sil function 'dont_promote_addronly_aggregate'
557+
sil @dont_promote_addronly_aggregate : $@convention(thin) () -> () {
558+
bb0:
559+
%11 = alloc_stack $Pair<ResilientTy, ()>
560+
%12 = struct_element_addr %11 : $*Pair<ResilientTy, ()>, #Pair.u
561+
%13 = load %12 : $*()
562+
%empty = tuple ()
563+
%14 = tuple (%empty : $(), %13 : $())
564+
dealloc_stack %11 : $*Pair<ResilientTy, ()>
565+
return undef : $()
566+
}
567+
568+
// CHECK-LABEL: sil @dont_promote_addronly_aggregate_2 : {{.*}} {
569+
// CHECK: alloc_stack
570+
// CHECK-LABEL: } // end sil function 'dont_promote_addronly_aggregate_2'
571+
sil @dont_promote_addronly_aggregate_2 : $@convention(thin) <T> () -> () {
572+
bb0:
573+
%11 = alloc_stack $Pair<T, ()>
574+
%12 = struct_element_addr %11 : $*Pair<T, ()>, #Pair.u
575+
%13 = load %12 : $*()
576+
%empty = tuple ()
577+
%14 = tuple (%empty : $(), %13 : $())
578+
dealloc_stack %11 : $*Pair<T, ()>
579+
return undef : $()
580+
}

0 commit comments

Comments
 (0)