Skip to content

Commit 2af31c7

Browse files
committed
[AddressLowering] Set the right yield operand.
Rather than always setting the 0th operand of a yield instruction, set the operand at the index of the original operand.
1 parent 8b8e916 commit 2af31c7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2610,7 +2610,7 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
26102610

26112611
void visitYieldInst(YieldInst *yield) {
26122612
SILValue addr = addrMat.materializeAddress(use->get());
2613-
yield->setOperand(0, addr);
2613+
yield->setOperand(use->getOperandNumber(), addr);
26142614
}
26152615

26162616
void visitValueMetatypeInst(ValueMetatypeInst *vmi) {

test/SILOptimizer/address_lowering.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,3 +1626,31 @@ bb0(%0 : @guaranteed $T):
16261626
return %6 : $U
16271627
}
16281628

1629+
// CHECK-LABEL: sil [ossa] @yield_two : {{.*}} {
1630+
// CHECK: tuple_element_addr
1631+
// CHECK: tuple_element_addr
1632+
// CHECK: [[KEY:%[^,]+]] = tuple_element_addr {{%[^,]+}} : $*(key: Key, value: Value), 0
1633+
// CHECK: [[VALUE:%[^,]+]] = tuple_element_addr {{%[^,]+}} : $*(key: Key, value: Value), 1
1634+
// CHECK: yield ([[KEY]] : $*Key, [[VALUE]] : $*Value)
1635+
// CHECK-LABEL: } // end sil function 'yield_two'
1636+
sil [ossa] @yield_two : $@yield_once @convention(method) <Key, Value> (@in_guaranteed Key, @in_guaranteed Value) -> (@yields @in_guaranteed Key, @yields @in_guaranteed Value) {
1637+
bb0(%0 : @guaranteed $Key, %1 : @guaranteed $Value):
1638+
%7 = copy_value %0 : $Key
1639+
%8 = copy_value %1 : $Value
1640+
%9 = tuple $(key: Key, value: Value) (%7, %8)
1641+
%10 = begin_borrow %9 : $(key: Key, value: Value)
1642+
%11 = tuple_extract %10 : $(key: Key, value: Value), 0
1643+
%12 = tuple_extract %10 : $(key: Key, value: Value), 1
1644+
yield (%11 : $Key, %12 : $Value), resume bb1, unwind bb2
1645+
1646+
bb1:
1647+
end_borrow %10 : $(key: Key, value: Value)
1648+
destroy_value %9 : $(key: Key, value: Value)
1649+
%17 = tuple ()
1650+
return %17 : $()
1651+
1652+
bb2:
1653+
end_borrow %10 : $(key: Key, value: Value)
1654+
destroy_value %9 : $(key: Key, value: Value)
1655+
unwind
1656+
}

0 commit comments

Comments
 (0)