Skip to content

Commit 8cb61d1

Browse files
Merge pull request #67423 from nate-chandler/opaque-values/20230719/2/all_stores_within_guaranteed_argument_lifetime
[AddressLowering] Exit range check for args early.
2 parents b1c5631 + 52dd6a5 commit 8cb61d1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ static bool isStoreCopy(SILValue value) {
384384
// - visit borrow introducers via visitBorrowIntroducers
385385
// - call ExtendedLiveness.compute on each borrow introducer
386386
if (llvm::any_of(roots, [&](SILValue root) {
387+
// Nothing is out of range of a function argument.
388+
if (isa<SILFunctionArgument>(root))
389+
return false;
390+
387391
// Handle forwarding phis conservatively rather than recursing.
388392
if (SILArgument::asPhi(root) && !BorrowedValue(root))
389393
return true;

test/SILOptimizer/address_lowering.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,31 @@ bb7:
10451045
return %23 : $()
10461046
}
10471047

1048+
// CHECK-LABEL: sil [ossa] @f163_testOpenedArchetype : {{.*}} {
1049+
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
1050+
// CHECK: [[ADDR:%[^,]+]] = alloc_stack $Optional<Any>
1051+
// CHECK: [[BORROW:%[^,]+]] = begin_borrow [lexical] [[INSTANCE]]
1052+
// CHECK: [[AN_ERROR:%[^,]+]] = open_existential_box [[BORROW]]
1053+
// CHECK: [[ANY_ADDR:%[^,]+]] = init_enum_data_addr [[ADDR]]
1054+
// CHECK: [[OPENED_ADDR:%[^,]+]] = init_existential_addr [[ANY_ADDR]]
1055+
// CHECK: copy_addr [[AN_ERROR]] to [init] [[OPENED_ADDR]]
1056+
// CHECK: inject_enum_addr [[ADDR]] : $*Optional<Any>, #Optional.some!enumelt
1057+
// CHECK: apply undef<Any>([[ADDR]])
1058+
// CHECK-LABEL: } // end sil function 'f163_testOpenedArchetype'
1059+
sil [ossa] @f163_testOpenedArchetype : $@convention(c) (@owned any Error) -> () {
1060+
block(%instance : @owned $any Error):
1061+
%borrow = begin_borrow [lexical] %instance : $any Error
1062+
%an_error = open_existential_box_value %borrow : $any Error to $@opened("55625EBA-9384-11ED-A0B0-32F16C24A34F", any Error) Self
1063+
%an_owned_error = copy_value %an_error : $@opened("55625EBA-9384-11ED-A0B0-32F16C24A34F", any Error) Self
1064+
%any = init_existential_value %an_owned_error : $@opened("55625EBA-9384-11ED-A0B0-32F16C24A34F", any Error) Self, $@opened("55625EBA-9384-11ED-A0B0-32F16C24A34F", any Error) Self, $Any
1065+
%some_any = enum $Optional<Any>, #Optional.some!enumelt, %any : $Any
1066+
apply undef<Any>(%some_any) : $@convention(thin) <T> (@in Optional<T>) -> ()
1067+
end_borrow %borrow : $any Error
1068+
destroy_value %instance : $any Error
1069+
%retval = tuple ()
1070+
return %retval : $()
1071+
}
1072+
10481073
// CHECK-LABEL: sil [ossa] @f170_compare : $@convention(thin) <T where T : Comparable> (@in_guaranteed T, @in_guaranteed T) -> @out T {
10491074
// CHECK: bb0(%0 : $*T, %1 : $*T, %2 : $*T):
10501075
// CHECK: [[WT:%.*]] = witness_method $T, #Comparable."<" : <Self where Self : Comparable> (Self.Type) -> (Self, Self) -> Builtin.Int1 : $@convention(witness_method: Comparable) <τ_0_0 where τ_0_0 : Comparable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> Builtin.Int1

0 commit comments

Comments
 (0)