Skip to content

Commit fb7990c

Browse files
committed
[move-only] Fix SILCombine to preserve value deinit
Fix a special case in visitReleaseValueInst for enum-with-deinit. (cherry picked from commit 58f96a9)
1 parent 75064b3 commit fb7990c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

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

1087+
// Do not remove a release that calls a value deinit.
1088+
if (hasValueDeinit(OperandTy))
1089+
return nullptr;
1090+
10871091
// Destroy value of an enum with a trivial payload or no-payload is a no-op.
10881092
if (auto *EI = dyn_cast<EnumInst>(Operand)) {
10891093
if (!EI->hasOperand() ||

test/SILOptimizer/sil_combine_moveonly.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,21 @@ bb0:
8181
%42 = tuple ()
8282
return %42 : $()
8383
}
84+
<<<<<<< HEAD
8485
>>>>>>> 536cba48be8 ([move-only] Fix SILOptimizer code motion to preserve value deinits)
86+
=======
87+
88+
// Test that a release of a trivial payload is not removed.
89+
//
90+
// CHECK-LABEL: sil hidden [noinline] @testEnumDeinitTrivialPayload : $@convention(thin) () -> () {
91+
// CHECK: release_value %{{.*}} : $MaybeFileDescriptor
92+
// CHECK-LABEL: } // end sil function 'testEnumDeinitTrivialPayload'
93+
sil hidden [noinline] @testEnumDeinitTrivialPayload : $@convention(thin) () -> () {
94+
bb0:
95+
%0 = enum $MaybeFileDescriptor, #MaybeFileDescriptor.nothing!enumelt // users: %2, %1
96+
debug_value %0 : $MaybeFileDescriptor, var, name "maybe" // id: %1
97+
release_value %0 : $MaybeFileDescriptor
98+
%9 = tuple ()
99+
return %9 : $()
100+
}
101+
>>>>>>> dcc1e6a5d85 ([move-only] Fix SILCombine to preserve value deinit)

0 commit comments

Comments
 (0)