Skip to content

Commit 54ebff3

Browse files
committed
[SILCombine] Handle indirect error in apply(conv).
Previously, only the indirect results and the parameters were handled. However, the indirect error doesn't show up in the list of indirect results (or in the list of parameters). But it sure does show up in the list of arguments. Here, that argument too is handled. rdar://127452206
1 parent d2a8128 commit 54ebff3

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
157157
auto context = AI.getFunction()->getTypeExpansionContext();
158158
auto oldOpRetTypes = substConventions.getIndirectSILResultTypes(context);
159159
auto newOpRetTypes = convertConventions.getIndirectSILResultTypes(context);
160+
auto oldIndirectErrorResultType =
161+
substConventions.getIndirectErrorResultType(context);
162+
auto newIndirectErrorResultType =
163+
convertConventions.getIndirectErrorResultType(context);
160164
auto oldOpParamTypes = substConventions.getParameterSILTypes(context);
161165
auto newOpParamTypes = convertConventions.getParameterSILTypes(context);
162166

@@ -186,7 +190,13 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
186190
++OpI, ++newRetI, ++oldRetI) {
187191
convertOp(Ops[OpI], *oldRetI, *newRetI);
188192
}
189-
193+
194+
if (oldIndirectErrorResultType) {
195+
assert(newIndirectErrorResultType);
196+
convertOp(Ops[OpI], oldIndirectErrorResultType, newIndirectErrorResultType);
197+
++OpI;
198+
}
199+
190200
auto newParamI = newOpParamTypes.begin();
191201
auto oldParamI = oldOpParamTypes.begin();
192202
for (auto e = newOpParamTypes.end(); newParamI != e;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -test-runner | %FileCheck %s
2+
3+
import Builtin
4+
5+
struct Input {}
6+
struct Output {}
7+
enum Nunca {}
8+
9+
sil @rdar127452206_callee : $@convention(thin) @Sendable @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output>
10+
11+
// CHECK-LABEL: sil @rdar127452206 : {{.*}} {
12+
// CHECK: bb0([[INPUT:%[^,]+]] :
13+
// CHECK: [[OUTPUT:%[^,]+]] = alloc_stack $Output
14+
// CHECK: [[NUNCA:%[^,]+]] = alloc_stack $Nunca
15+
// CHECK: [[OUTPUT_AS_OUTPUT:%[^,]+]] = unchecked_addr_cast [[OUTPUT]]
16+
// CHECK: [[NUNCA_AS_NUNCA:%[^,]+]] = unchecked_addr_cast [[NUNCA]]
17+
// CHECK: [[INPUT_AS_INPUT:%[^,]+]] = unchecked_addr_cast [[INPUT]]
18+
// CHECK: apply [nothrow] {{%[^,]+}}([[OUTPUT_AS_OUTPUT]], [[NUNCA_AS_NUNCA]], [[INPUT_AS_INPUT]])
19+
// CHECK-LABEL: } // end sil function 'rdar127452206'
20+
sil @rdar127452206 : $@convention(thin) (@in Input) -> () {
21+
entry(%input : $*Input):
22+
%output = alloc_stack $Output
23+
%nunca = alloc_stack $Nunca
24+
%callee = function_ref @rdar127452206_callee : $@convention(thin) @Sendable @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output>
25+
%convert = convert_function %callee : $@convention(thin) @Sendable @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output> to $@convention(thin) @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output> // user: %216
26+
specify_test "sil_combine_instruction @instruction[4]"
27+
apply [nothrow] %convert(%output, %nunca, %input) : $@convention(thin) @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output>
28+
dealloc_stack %nunca : $*Nunca
29+
dealloc_stack %output : $*Output
30+
%retval = tuple ()
31+
return %retval : $()
32+
}
33+
34+

0 commit comments

Comments
 (0)