Skip to content

Commit f276ebf

Browse files
committed
[Mem2Reg] Only lifetime canonicalize in OSSA.
Bail both on collecting stores and canonicalizing values if the function being optimized doesn't have ownership.
1 parent 53da675 commit f276ebf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,8 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
21532153
void MemoryToRegisters::collectStoredValues(AllocStackInst *asi,
21542154
StackList<SILValue> &owned,
21552155
StackList<SILValue> &guaranteed) {
2156+
if (!f.hasOwnership())
2157+
return;
21562158
for (auto *use : asi->getUses()) {
21572159
auto *user = use->getUser();
21582160
if (auto *si = dyn_cast<StoreInst>(user)) {
@@ -2166,6 +2168,8 @@ void MemoryToRegisters::collectStoredValues(AllocStackInst *asi,
21662168
void MemoryToRegisters::canonicalizeValueLifetimes(
21672169
StackList<SILValue> &owned, StackList<SILValue> &guaranteed,
21682170
BasicBlockSetVector &livePhiBlocks) {
2171+
if (!f.hasOwnership())
2172+
return;
21692173
if (Mem2RegDisableLifetimeCanonicalization)
21702174
return;
21712175

test/SILOptimizer/mem2reg.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,16 @@ sil @load_from_uninitialized_empty : $@convention(thin) () -> (Pair<Pair<EmptySt
518518
dealloc_stack %addr : $*(Pair<Pair<EmptyStruct, EmptyStruct>, EmptyStruct>, (EmptyStruct, EmptyStruct), EmptyStruct)
519519
return %value : $(Pair<Pair<EmptyStruct, EmptyStruct>, EmptyStruct>, (EmptyStruct, EmptyStruct), EmptyStruct)
520520
}
521+
522+
523+
// CHECK-LABEL: sil @dont_canonicalize_undef : {{.*}} {
524+
// CHECK: [[RETVAL:%[^,]+]] = tuple
525+
// CHECK: return [[RETVAL]]
526+
// CHECK-LABEL: } // end sil function 'dont_canonicalize_undef'
527+
sil @dont_canonicalize_undef : $@convention(thin) () -> () {
528+
%addr = alloc_stack $()
529+
store undef to %addr : $*()
530+
dealloc_stack %addr : $*()
531+
%retval = tuple ()
532+
return %retval : $()
533+
}

0 commit comments

Comments
 (0)