Skip to content

Commit 7ad765e

Browse files
committed
[move-only] Fix SILCombine to preserve value deinit
Fix a special case in visitReleaseValueInst for enum-with-deinit.
1 parent 10de5eb commit 7ad765e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,10 @@ SILInstruction *SILCombiner::visitReleaseValueInst(ReleaseValueInst *RVI) {
858858
SILValue Operand = RVI->getOperand();
859859
SILType OperandTy = Operand->getType();
860860

861+
// Do not remove a release that calls a value deinit.
862+
if (hasValueDeinit(OperandTy))
863+
return nullptr;
864+
861865
// Destroy value of an enum with a trivial payload or no-payload is a no-op.
862866
if (auto *EI = dyn_cast<EnumInst>(Operand)) {
863867
if (!EI->hasOperand() ||

test/SILOptimizer/sil_combine_moveonly.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ bb0:
5757
%42 = tuple ()
5858
return %42 : $()
5959
}
60+
61+
// Test that a release of a trivial payload is not removed.
62+
//
63+
// CHECK-LABEL: sil hidden [noinline] @testEnumDeinitTrivialPayload : $@convention(thin) () -> () {
64+
// CHECK: release_value %{{.*}} : $MaybeFileDescriptor
65+
// CHECK-LABEL: } // end sil function 'testEnumDeinitTrivialPayload'
66+
sil hidden [noinline] @testEnumDeinitTrivialPayload : $@convention(thin) () -> () {
67+
bb0:
68+
%0 = enum $MaybeFileDescriptor, #MaybeFileDescriptor.nothing!enumelt // users: %2, %1
69+
debug_value %0 : $MaybeFileDescriptor, var, name "maybe" // id: %1
70+
release_value %0 : $MaybeFileDescriptor
71+
%9 = tuple ()
72+
return %9 : $()
73+
}

0 commit comments

Comments
 (0)