Skip to content

Commit 4f16bb1

Browse files
committed
[Mem2Reg] Don't canonicalize undef.
They aren't the kind of values whose lifetimes are eligible for canonicalization. rdar://113121424
1 parent f276ebf commit 4f16bb1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,8 @@ void MemoryToRegisters::canonicalizeValueLifetimes(
21952195
/*pruneDebug=*/true, /*maximizeLifetime=*/!f.shouldOptimize(), &f,
21962196
accessBlockAnalysis, domInfo, calleeAnalysis, deleter);
21972197
for (auto value : owned) {
2198+
if (isa<SILUndef>(value))
2199+
continue;
21982200
auto root = CanonicalizeOSSALifetime::getCanonicalCopiedDef(value);
21992201
if (auto *copy = dyn_cast<CopyValueInst>(root)) {
22002202
if (SILValue borrowDef = CanonicalizeBorrowScope::getCanonicalBorrowedDef(
@@ -2207,6 +2209,8 @@ void MemoryToRegisters::canonicalizeValueLifetimes(
22072209
}
22082210
CanonicalizeBorrowScope borrowCanonicalizer(&f, deleter);
22092211
for (auto value : guaranteed) {
2212+
if (isa<SILUndef>(value))
2213+
continue;
22102214
auto borrowee = CanonicalizeBorrowScope::getCanonicalBorrowedDef(value);
22112215
if (!borrowee)
22122216
continue;

test/SILOptimizer/mem2reg_ossa.sil

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,3 +730,15 @@ exit:
730730
%retval = tuple ()
731731
return %retval : $()
732732
}
733+
734+
// CHECK-LABEL: sil [ossa] @dont_canonicalize_undef : {{.*}} {
735+
// CHECK: [[RETVAL:%[^,]+]] = tuple
736+
// CHECK: return [[RETVAL]]
737+
// CHECK-LABEL: } // end sil function 'dont_canonicalize_undef'
738+
sil [ossa] @dont_canonicalize_undef : $@convention(thin) () -> () {
739+
%addr = alloc_stack $()
740+
store undef to [trivial] %addr : $*()
741+
dealloc_stack %addr : $*()
742+
%retval = tuple ()
743+
return %retval : $()
744+
}

0 commit comments

Comments
 (0)