Skip to content

Commit bfdeb57

Browse files
committed
LICM: fix handling of stores of Optional.none in OSSA
Currently we don't support hoisting ownership instructions. But the check was missing a store of Optional.none because such a value has no ownership even if the optional is not trivial. Fixes a SIL verifier crash. #79491
1 parent b352d17 commit bfdeb57

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,17 @@ void LoopTreeOptimization::analyzeCurrentLoop(
909909
LoadsAndStores.push_back(&Inst);
910910
break;
911911
case SILInstructionKind::StoreInst: {
912-
Stores.push_back(cast<StoreInst>(&Inst));
912+
auto *store = cast<StoreInst>(&Inst);
913+
switch (store->getOwnershipQualifier()) {
914+
case StoreOwnershipQualifier::Assign:
915+
case StoreOwnershipQualifier::Init:
916+
// Currently not supported.
917+
continue;
918+
case StoreOwnershipQualifier::Unqualified:
919+
case StoreOwnershipQualifier::Trivial:
920+
break;
921+
}
922+
Stores.push_back(store);
913923
LoadsAndStores.push_back(&Inst);
914924
checkSideEffects(Inst, sideEffects, sideEffectsInBlock);
915925
break;

test/SILOptimizer/licm.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,3 +1639,31 @@ bb3:
16391639
%15 = tuple ()
16401640
return %15
16411641
}
1642+
1643+
// Hoisting non-trivial loads/stores is currently not supported in OSSA.
1644+
// CHECK-LABEL: sil [ossa] @store_of_optional_none :
1645+
// CHECK: bb2:
1646+
// CHECK: store %0 to [assign] %1
1647+
// CHECK: bb3:
1648+
// CHECK-LABEL: } // end sil function 'store_of_optional_none'
1649+
sil [ossa] @store_of_optional_none : $@convention(thin) () -> () {
1650+
bb0:
1651+
%0 = enum $Optional<String>, #Optional.none!enumelt
1652+
%1 = alloc_stack $Optional<String>
1653+
store %0 to [init] %1
1654+
br bb1
1655+
1656+
bb1:
1657+
cond_br undef, bb2, bb3
1658+
1659+
bb2:
1660+
store %0 to [assign] %1
1661+
br bb1
1662+
1663+
bb3:
1664+
destroy_addr %1
1665+
dealloc_stack %1
1666+
%r = tuple()
1667+
return %r : $()
1668+
}
1669+

0 commit comments

Comments
 (0)