Skip to content

Commit 2361270

Browse files
committed
Fix ownership kind of select_value
1 parent 0a6dc67 commit 2361270

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ OPERAND_OWNERSHIP(TrivialUse, PointerToAddress)
180180
OPERAND_OWNERSHIP(TrivialUse, ProjectBlockStorage)
181181
OPERAND_OWNERSHIP(TrivialUse, RawPointerToRef)
182182
OPERAND_OWNERSHIP(TrivialUse, SelectEnumAddr)
183+
// select_value is support for trivial integral types only.
184+
OPERAND_OWNERSHIP(TrivialUse, SelectValue)
183185
OPERAND_OWNERSHIP(TrivialUse, StructElementAddr)
184186
OPERAND_OWNERSHIP(TrivialUse, SwitchEnumAddr)
185187
OPERAND_OWNERSHIP(TrivialUse, SwitchValue)
@@ -422,23 +424,6 @@ OperandOwnershipClassifier::visitSelectEnumInst(SelectEnumInst *i) {
422424
/*allowUnowned*/true);
423425
}
424426

425-
OperandOwnership
426-
OperandOwnershipClassifier::visitSelectValueInst(SelectValueInst *i) {
427-
if (getValue() == i->getDefaultResult())
428-
return OperandOwnership::GuaranteedForwarding;
429-
430-
for (unsigned idx = 0, endIdx = i->getNumCases(); idx < endIdx; ++idx) {
431-
SILValue casevalue;
432-
SILValue result;
433-
std::tie(casevalue, result) = i->getCase(idx);
434-
435-
if (getValue() == casevalue) {
436-
return OperandOwnership::GuaranteedForwarding;
437-
}
438-
}
439-
return OperandOwnership::TrivialUse;
440-
}
441-
442427
OperandOwnership OperandOwnershipClassifier::visitBranchInst(BranchInst *bi) {
443428
ValueOwnershipKind destBlockArgOwnershipKind =
444429
bi->getDestBB()->getArgument(getOperandIndex())->getOwnershipKind();

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ CONSTANT_OWNERSHIP_INST(None, RefElementAddr)
128128
CONSTANT_OWNERSHIP_INST(None, RefTailAddr)
129129
CONSTANT_OWNERSHIP_INST(None, RefToRawPointer)
130130
CONSTANT_OWNERSHIP_INST(None, SelectEnumAddr)
131+
CONSTANT_OWNERSHIP_INST(None, SelectValue)
131132
CONSTANT_OWNERSHIP_INST(None, StringLiteral)
132133
CONSTANT_OWNERSHIP_INST(None, StructElementAddr)
133134
CONSTANT_OWNERSHIP_INST(None, SuperMethod)
@@ -166,7 +167,6 @@ CONSTANT_OWNERSHIP_INST(None, ExtractExecutor)
166167
}
167168
CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, StructExtract)
168169
CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, TupleExtract)
169-
CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, SelectValue)
170170
CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, DifferentiableFunctionExtract)
171171
CONSTANT_OR_NONE_OWNERSHIP_INST(Guaranteed, LinearFunctionExtract)
172172
// OpenExistentialValue opens the boxed value inside an existential

test/SIL/OwnershipVerifier/use_verifier.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ extension ClassProtConformingRef : ClassProt {}
117117
// Test Cases //
118118
////////////////
119119

120+
sil [ossa] @test_select_value : $@convention(thin) (Builtin.Word) -> Builtin.Word {
121+
bb0(%0 : $Builtin.Word):
122+
123+
%1 = integer_literal $Builtin.Word, 1
124+
%2 = integer_literal $Builtin.Word, 2
125+
%3 = integer_literal $Builtin.Word, 3
126+
%4 = integer_literal $Builtin.Word, 4
127+
%5 = integer_literal $Builtin.Word, 5
128+
%6 = integer_literal $Builtin.Word, 6
129+
%11 = integer_literal $Builtin.Word, 11
130+
%22 = integer_literal $Builtin.Word, 22
131+
%33 = integer_literal $Builtin.Word, 33
132+
%44 = integer_literal $Builtin.Word, 44
133+
%55 = integer_literal $Builtin.Word, 55
134+
%66 = integer_literal $Builtin.Word, 66
135+
136+
// CHECK: select_value %{{.*}} : $Builtin.Word, case %{{.*}}: %{{.*}}, case %{{.*}}: %{{.*}}, case %{{.*}}: %{{.*}}, case %{{.*}}: %{{.*}}, case %{{.*}}: %{{.*}}, default %{{.*}} : $Builtin.Word
137+
%10 = select_value %1: $Builtin.Word, case %1: %11, case %2: %22, case %4: %44, case %5: %55, case %6: %66, default %33 : $Builtin.Word
138+
139+
// CHECK: return
140+
return %10 : $Builtin.Word
141+
}
120142
// Make sure that guaranteed args do not have a consuming use.
121143
sil [ossa] @direct_guaranteed_arg_doesnt_have_consuming_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
122144
bb0(%0 : @guaranteed $Builtin.NativeObject):
@@ -1432,3 +1454,4 @@ bb0(%0 : @unowned $ThreeDifferingPayloadEnum):
14321454
%1 = unchecked_enum_data %0 : $ThreeDifferingPayloadEnum, #ThreeDifferingPayloadEnum.trivial_payload!enumelt
14331455
return %1 : $Builtin.Int32
14341456
}
1457+

0 commit comments

Comments
 (0)