Skip to content

Commit b1fc313

Browse files
authored
Merge pull request #74802 from meg-gupta/temprvalueedgecase
Allow TempRValueOpt of lexical alloc_stacks when base of copy source is @in_guaranteed
2 parents a451523 + 32e72a6 commit b1fc313

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

lib/SILOptimizer/Transforms/TempRValueElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ void TempRValueOptPass::tryOptimizeCopyIntoTemp(CopyAddrInst *copyInst) {
528528
if (!storage.base)
529529
return;
530530
if (auto *arg = dyn_cast<SILFunctionArgument>(storage.base))
531-
if (arg->getOwnershipKind() != OwnershipKind::Guaranteed)
531+
if (!arg->getArgumentConvention().isGuaranteedConventionInCallee())
532532
return;
533533
}
534534

test/SILOptimizer/assemblyvision_remark/cast_remarks_objc.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ public func forcedCast2<NS, T>(_ ns: NS) -> T {
2121
let x = ns
2222
return x as! T // expected-remark @:12 {{unconditional runtime cast of value with type 'NS' to 'T'}}
2323
// expected-note @-4:34 {{of 'ns'}}
24-
// expected-note @-3:7 {{of 'x'}}
2524
}
2625

2726
public func forcedCast3<NS, T>(_ ns: NS) -> T {
2827
// Make sure the colon info is right so that the arrow is under the a.
2928
var x = ns // expected-warning {{variable 'x' was never mutated}}
3029
return x as! T // expected-remark @:12 {{unconditional runtime cast of value with type 'NS' to 'T'}}
3130
// expected-note @-4:34 {{of 'ns'}}
32-
// expected-note @-3:7 {{of 'x'}}
3331
}
3432

3533
public func forcedCast4<NS, T>(_ ns: NS, _ ns2: NS) -> T {
@@ -52,15 +50,13 @@ public func condCast2<NS, T>(_ ns: NS) -> T? {
5250
let x = ns
5351
return x as? T // expected-remark @:12 {{conditional runtime cast of value with type 'NS' to 'T'}}
5452
// expected-note @-4:32 {{of 'ns'}}
55-
// expected-note @-3:7 {{of 'x'}}
5653
}
5754

5855
public func condCast3<NS, T>(_ ns: NS) -> T? {
5956
// Make sure the colon info is right so that the arrow is under the a.
6057
var x = ns // expected-warning {{variable 'x' was never mutated}}
6158
return x as? T // expected-remark @:12 {{conditional runtime cast of value with type 'NS' to 'T'}}
6259
// expected-note @-4:32 {{of 'ns'}}
63-
// expected-note @-3:7 {{of 'x'}}
6460
}
6561

6662
public func condCast4<NS, T>(_ ns: NS, _ ns2: NS) -> T? {

test/SILOptimizer/temp_rvalue_opt_ossa.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,19 @@ entry(%instance : @guaranteed $OtherClass):
18041804
return %retval : $()
18051805
}
18061806

1807+
// CHECK-LABEL: sil [ossa] @copy_addr__lexical_alloc_stack_temporary_in_guaranteed_function_arg : {{.*}} {
1808+
// CHECK-NOT: alloc_stack
1809+
// CHECK-LABEL: } // end sil function 'copy_addr__lexical_alloc_stack_temporary_in_guaranteed_function_arg'
1810+
sil [ossa] @copy_addr__lexical_alloc_stack_temporary_in_guaranteed_function_arg : $@convention(thin) (@in_guaranteed Klass) -> () {
1811+
entry(%instance : $*Klass):
1812+
%addr = alloc_stack [lexical] $Klass
1813+
copy_addr %instance to [init] %addr : $*Klass
1814+
destroy_addr %addr : $*Klass
1815+
dealloc_stack %addr : $*Klass
1816+
%retval = tuple ()
1817+
return %retval : $()
1818+
}
1819+
18071820
// Lexical alloc_stacks can't be eliminated even if their source is a function
18081821
// argument if that function argument is inout.
18091822
// CHECK-LABEL: sil [ossa] @copy_addr__lexical_alloc_stack_temporary__inout_function_arg : {{.*}} {

0 commit comments

Comments
 (0)