Skip to content

Commit 781953f

Browse files
Merge pull request #62078 from nate-chandler/opaque-values/1/20221112
[AddressLowering] Create copy_addr after store.
2 parents 13d933e + 1023583 commit 781953f

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,9 @@ void UseRewriter::rewriteStore(SILValue srcVal, SILValue destAddr,
30763076
isTake = IsNotTake;
30773077
}
30783078
}
3079-
builder.createCopyAddr(loc, srcAddr, destAddr, isTake, isInit);
3079+
SILBuilderWithScope::insertAfter(storeInst, [&](auto &builder) {
3080+
builder.createCopyAddr(loc, srcAddr, destAddr, isTake, isInit);
3081+
});
30803082
pass.deleter.forceDelete(storeInst);
30813083
}
30823084

test/SILOptimizer/address_lowering.sil

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,8 @@ bb0(%0 : @owned $P):
950950
// CHECK-LABEL: sil [ossa] @f161_testOpenedArchetype : $@convention(thin) (@in any P) -> () {
951951
// CHECK: bb0(%0 : $*any P):
952952
// CHECK: [[ALLOCP:%.*]] = alloc_stack $any P, var, name "q"
953-
// CHECK: copy_addr %0 to [init] [[ALLOCP]] : $*any P
954953
// CHECK: debug_value %0 : $*any P, var, name "q"
954+
// CHECK: copy_addr %0 to [init] [[ALLOCP]] : $*any P
955955
// CHECK: [[OPEN:%.*]] = open_existential_addr immutable_access %0 : $*any P to $*@opened("EF755EF2-B636-11E7-B7B4-A45E60ECC541", any P) Self
956956
// CHECK: [[OPTIONAL:%.*]] = alloc_stack $Optional<@opened("EF755EF2-B636-11E7-B7B4-A45E60ECC541", any P) Self>
957957
// CHECK: witness_method $@opened("EF755EF2-B636-11E7-B7B4-A45E60ECC541", any P) Self, #P.foo : <Self where Self : P> (Self) -> () -> (), [[OPEN]] : $*@opened("EF755EF2-B636-11E7-B7B4-A45E60ECC541", any P) Self : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
@@ -1901,6 +1901,29 @@ exit:
19011901
return %retval : $()
19021902
}
19031903

1904+
// CHECK-LABEL: sil hidden [ossa] @test_store_1 : {{.*}} {
1905+
// CHECK: [[MAYBE_ADDR:%[^,]+]] = alloc_stack $Optional<Self>
1906+
// CHECK: [[LOAD_ADDR:%[^,]+]] = alloc_stack $Self
1907+
// CHECK: [[ADDR:%[^,]+]] = alloc_stack $Self, var, name "self"
1908+
// CHECK: [[INSTANCE_ADDR:%[^,]+]] = unchecked_take_enum_data_addr [[MAYBE_ADDR]] : $*Optional<Self>, #Optional.some!enumelt
1909+
// CHECK: debug_value [[INSTANCE_ADDR]] : $*Self, var, name "self", expr op_deref
1910+
// CHECK: copy_addr [take] [[INSTANCE_ADDR]] to [init] [[ADDR]]
1911+
// CHECK: copy_addr [[ADDR]] to [init] [[LOAD_ADDR]]
1912+
// CHECK-LABEL: } // end sil function 'test_store_1'
1913+
sil hidden [ossa] @test_store_1 : $@convention(thin) <Self> () -> () {
1914+
bb0:
1915+
%addr = alloc_stack $Self, var, name "self"
1916+
%maybe = apply undef<Self>() : $@convention(thin) <τ_0_0> () -> @out Optional<τ_0_0>
1917+
%instance = unchecked_enum_data %maybe : $Optional<Self>, #Optional.some!enumelt
1918+
store %instance to [init] %addr : $*Self
1919+
%load = load [copy] %addr : $*Self
1920+
destroy_addr %addr : $*Self
1921+
dealloc_stack %addr : $*Self
1922+
destroy_value %load : $Self
1923+
%retval = tuple ()
1924+
return %retval : $()
1925+
}
1926+
19041927
// CHECK-LABEL: sil hidden [ossa] @test_unchecked_bitwise_cast :
19051928
// CHECK: bb0(%0 : $*U, %1 : $*T, %2 : $@thick U.Type):
19061929
// CHECK: [[STK:%.*]] = alloc_stack $T

test/SILOptimizer/address_lowering_phi.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ bb3(%phi : @owned $T):
481481
// CHECK: [[VAR:%[^,]+]] = alloc_stack [lexical] $Value, var, name "value"
482482
// CHECK: cond_br undef, bb2, bb1
483483
// CHECK: bb3:
484-
// CHECK: copy_addr [take] [[TEMP]] to [init] [[VAR]]
485484
// CHECK: debug_value [[TEMP]] : $*Value, var, name "value"
485+
// CHECK: copy_addr [take] [[TEMP]] to [init] [[VAR]]
486486
// CHECK-LABEL: } // end sil function 'f100_store_phi'
487487
sil [ossa] @f100_store_phi : $@convention(thin) <Value> (@in Value) -> () {
488488
entry(%instance : @owned $Value):

0 commit comments

Comments
 (0)