Skip to content

Commit 35113d8

Browse files
committed
[AddressLowering] Fix partial_apply arg indexing.
When rewriting arguments, the index used is into the callee's argument list. For full applies, that is identical to the index into the instruction's argument list. For partial applies, it is not. Previously, though, the index was used as if it were an index into the instruction's argument list to get an argument ref. Here, use instead the newly added convenience to get the argument ref using the index into the callee's arguments.
1 parent 5c31339 commit 35113d8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ bool CallArgRewriter::rewriteArguments() {
22002200
endArgIdx = argIdx + apply.getNumArguments();
22012201
argIdx < endArgIdx; ++argIdx) {
22022202

2203-
Operand &operand = apply.getArgumentRef(argIdx);
2203+
Operand &operand = apply.getArgumentRefAtCalleeArgIndex(argIdx);
22042204
// Ignore arguments that have already been rewritten with an address.
22052205
if (operand.get()->getType().isAddress())
22062206
continue;

test/SILOptimizer/address_lowering.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,22 @@ sil [ossa] @test_partial_apply_4_loadable_stack : $() -> () {
26192619
return %retval : $()
26202620
}
26212621

2622+
// CHECK-LABEL: sil [ossa] @test_partial_apply_5_indexing : {{.*}} {
2623+
// CHECK: {{bb[0-9]+}}([[C:%[^,]+]] :
2624+
// CHECK: [[CALLEE:%[^,]+]] = function_ref @test_partial_apply_5_indexing_callee
2625+
// CHECK: [[CLOSURE:%[^,]+]] = partial_apply [callee_guaranteed] [[CALLEE]]([[C]])
2626+
// CHECK: destroy_value [[CLOSURE]]
2627+
// CHECK-LABEL: } // end sil function 'test_partial_apply_5_indexing'
2628+
sil @test_partial_apply_5_indexing_callee : $@convention(thin) (@inout Int, @guaranteed Klass) -> (@out Int)
2629+
sil [ossa] @test_partial_apply_5_indexing : $@convention(thin) (@owned Klass) -> () {
2630+
bb0(%c : @owned $Klass):
2631+
%callee = function_ref @test_partial_apply_5_indexing_callee : $@convention(thin) (@inout Int, @guaranteed Klass) -> (@out Int)
2632+
%closure = partial_apply [callee_guaranteed] %callee(%c) : $@convention(thin) (@inout Int, @guaranteed Klass) -> (@out Int)
2633+
destroy_value %closure : $@callee_guaranteed (@inout Int) -> (@out Int)
2634+
%retval = tuple ()
2635+
return %retval : $()
2636+
}
2637+
26222638
// CHECK-LABEL: sil hidden [ossa] @test_store_1 : {{.*}} {
26232639
// CHECK: [[MAYBE_ADDR:%[^,]+]] = alloc_stack $Optional<Self>
26242640
// CHECK: [[LOAD_ADDR:%[^,]+]] = alloc_stack $Self

0 commit comments

Comments
 (0)