Skip to content

Commit f1d66e3

Browse files
authored
Merge pull request #78233 from eeckstein/ossa-simplify-alloc-stack
SILCombine: enable alloc_stack optimization for OSSA
2 parents d5bb068 + 69b16fa commit f1d66e3

File tree

4 files changed

+118
-125
lines changed

4 files changed

+118
-125
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,6 @@ bool SILCombiner::optimizeStackAllocatedEnum(AllocStackInst *AS) {
629629
}
630630

631631
SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
632-
if (AS->getFunction()->hasOwnership())
633-
return nullptr;
634-
635632
if (optimizeStackAllocatedEnum(AS))
636633
return nullptr;
637634

test/SILOptimizer/sil_combine_enum_addr_ossa.sil

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import Builtin
66
import Swift
77

88
// CHECK-LABEL: sil [ossa] @convert_inject_enum_addr_select_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout, @in_guaranteed any CustomStringConvertible) -> ()
9-
// XHECK-NOT: init_existential_addr
10-
// XHECK-NOT: inject_enum_addr
11-
// XHECK-NOT: select_enum_addr
12-
// XHECK-NOT: unchecked_take_enum_data_addr
13-
// XHECK: return
9+
// CHECK-NOT: init_existential_addr
10+
// CHECK-NOT: inject_enum_addr
11+
// CHECK-NOT: select_enum_addr
12+
// CHECK-NOT: unchecked_take_enum_data_addr
13+
// CHECK: return
1414
// CHEcK: } // end sil function 'convert_inject_enum_addr_select_enum_addr_into_cond_br'
1515
sil [ossa] @convert_inject_enum_addr_select_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout, @in_guaranteed CustomStringConvertible) -> () {
1616
bb0(%0 : $*Int, %1 : $*_Stdout, %1a : $*CustomStringConvertible):
@@ -48,12 +48,12 @@ bb2:
4848

4949

5050
// CHECK-LABEL: sil [ossa] @convert_inject_enum_addr_switch_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout, @in_guaranteed any CustomStringConvertible) -> ()
51-
// XHECK-NOT: init_existential_addr
52-
// XHECK-NOT: inject_enum_addr
53-
// XHECK-NOT: switch_enum_addr
54-
// XHECK-NOT: unchecked_take_enum_data_addr
55-
// XHECK: return
56-
// XHECK: } // end sil function 'convert_inject_enum_addr_switch_enum_addr_into_cond_br'
51+
// CHECK-NOT: init_existential_addr
52+
// CHECK-NOT: inject_enum_addr
53+
// CHECK-NOT: switch_enum_addr
54+
// CHECK-NOT: unchecked_take_enum_data_addr
55+
// CHECK: return
56+
// CHECK: } // end sil function 'convert_inject_enum_addr_switch_enum_addr_into_cond_br'
5757
sil [ossa] @convert_inject_enum_addr_switch_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout, @in_guaranteed CustomStringConvertible) -> () {
5858
bb0(%0 : $*Int, %1 : $*_Stdout, %1a : $*CustomStringConvertible):
5959
%2 = alloc_stack $CustomStringConvertible
@@ -92,14 +92,12 @@ bb3:
9292
// simplify-cfg that has not been updated yet for ossa.
9393
//
9494
// CHECK-LABEL: sil [ossa] @convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> ()
95-
// XHECK: checked_cast_addr_br
96-
// XHECK: } // end sil function 'convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br'
97-
// xXHECK: store
98-
// xXHECK-NOT: checked_cast_addr_br
99-
// xXHECK-NOT: bb1
100-
// xXHECK: inject_enum_addr %{{.*}} : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
101-
// xXHECK: dealloc_stack
102-
// xXHECK: return
95+
// CHECK: store
96+
// CHECK-NOT: checked_cast_addr_br
97+
// CHECK-NOT: bb1
98+
// CHECK: inject_enum_addr %{{.*}}, #Optional.some!enumelt
99+
// CHECK: dealloc_stack
100+
// CHECK: } // end sil function 'convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br'
103101
sil [ossa] @convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> () {
104102
bb0(%0 : $*Int, %1 : $*_Stdout):
105103
%2 = alloc_stack $CustomStringConvertible
@@ -195,14 +193,12 @@ bb22:
195193
// yet for OSSA so just validate we don't optimize this.
196194
//
197195
// CHECK-LABEL: sil [ossa] @convert_checked_cast_addr_br_with_private_type : $@convention(thin) (@in B, @inout _Stdout) -> ()
198-
// XHECK: checked_cast_addr_br
199-
// XHECK: } // end sil function 'convert_checked_cast_addr_br_with_private_type'
200-
// xXHECK: store
201-
// xXHECK-NOT: checked_cast_addr_br
202-
// xXHECK-NOT: bb1
203-
// xXHECK: inject_enum_addr %{{.*}} : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
204-
// xXHECK: dealloc_stack
205-
// xXHECK: return
196+
// CHECK: store
197+
// CHECK-NOT: checked_cast_addr_br
198+
// CHECK-NOT: bb1
199+
// CHECK: inject_enum_addr %{{.*}}, #Optional.none!enumelt
200+
// CHECK: dealloc_stack
201+
// CHECK: } // end sil function 'convert_checked_cast_addr_br_with_private_type'
206202
sil [ossa] @convert_checked_cast_addr_br_with_private_type : $@convention(thin) (@in B, @inout _Stdout) -> () {
207203
bb0(%0 : $*B, %1 : $*_Stdout):
208204
%2 = alloc_stack $CustomStringConvertible

test/SILOptimizer/sil_combine_enums_ossa.sil

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ bb0(%0 : $*G<T>):
147147
}
148148

149149
// CHECK-LABEL: sil [ossa] @canonicalize_init_enum_data_addr
150-
// XHECK-NOT: init_enum_data_addr
151-
// XHECK-NOT: inject_enum_addr
152-
// XHECK: enum $Optional<Int32>, #Optional.some!enumelt
153-
// XHECK-NOT: inject_enum_addr
154-
// XHECK: return
150+
// CHECK-NOT: init_enum_data_addr
151+
// CHECK-NOT: inject_enum_addr
152+
// CHECK: enum $Optional<Int32>, #Optional.some!enumelt
153+
// CHECK-NOT: inject_enum_addr
154+
// CHECK: return
155155
sil [ossa] @canonicalize_init_enum_data_addr : $@convention(thin) (@inout Int32, Builtin.Int32, Optional<Int32>) -> Int32 {
156156
bb0(%0 : $*Int32, %1 : $Builtin.Int32, %2 : $Optional<Int32>):
157157
%s1 = alloc_stack $Optional<Int32>
@@ -171,11 +171,11 @@ bb0(%0 : $*Int32, %1 : $Builtin.Int32, %2 : $Optional<Int32>):
171171
}
172172

173173
// CHECK-LABEL: sil [ossa] @canonicalize_init_enum_data_addr
174-
// XHECK-NOT: init_enum_data_addr
175-
// XHECK-NOT: inject_enum_addr
176-
// XHECK: enum $Optional<SomeClass>, #Optional.some!enumelt
177-
// XHECK-NOT: inject_enum_addr
178-
// XHECK: return
174+
// CHECK-NOT: init_enum_data_addr
175+
// CHECK-NOT: inject_enum_addr
176+
// CHECK: enum $Optional<SomeClass>, #Optional.some!enumelt
177+
// CHECK-NOT: inject_enum_addr
178+
// CHECK: return
179179
sil [ossa] @canonicalize_init_enum_data_addr_non_trivial : $@convention(thin) (@inout SomeClass, @owned Optional<SomeClass>) -> @owned Optional<SomeClass> {
180180
bb0(%0 : $*SomeClass, %2 : @owned $Optional<SomeClass>):
181181
%s1 = alloc_stack $Optional<SomeClass>
@@ -194,11 +194,11 @@ bb0(%0 : $*SomeClass, %2 : @owned $Optional<SomeClass>):
194194
}
195195

196196
// CHECK-LABEL: sil [ossa] @canonicalize_init_enum_data_addr_diff_basic_blocks
197-
// XHECK-NOT: init_enum_data_addr
198-
// XHECK-NOT: inject_enum_addr
199-
// XHECK: enum $Optional<Int32>, #Optional.some!enumelt
200-
// XHECK-NOT: inject_enum_addr
201-
// XHECK: return
197+
// CHECK-NOT: init_enum_data_addr
198+
// CHECK-NOT: inject_enum_addr
199+
// CHECK: enum $Optional<Int32>, #Optional.some!enumelt
200+
// CHECK-NOT: inject_enum_addr
201+
// CHECK: return
202202
sil [ossa] @canonicalize_init_enum_data_addr_diff_basic_blocks : $@convention(thin) (@inout Int32, Builtin.Int32, Optional<Int32>) -> Int32 {
203203
bb0(%0 : $*Int32, %1 : $Builtin.Int32, %2 : $Optional<Int32>):
204204
%s1 = alloc_stack $Optional<Int32>
@@ -221,10 +221,10 @@ bb1: // Preds: bb0
221221
}
222222

223223
// CHECK-LABEL: sil [ossa] @fail_to_canonicalize_init_enum_data_addr_reach_entry
224-
// XHECK: init_enum_data_addr
225-
// XHECK: inject_enum_addr
226-
// XHECK-NOT: enum $Optional<Int32>, #Optional.some!enumelt
227-
// XHECK: return
224+
// CHECK: init_enum_data_addr
225+
// CHECK: inject_enum_addr
226+
// CHECK-NOT: enum $Optional<Int32>, #Optional.some!enumelt
227+
// CHECK: return
228228
sil [ossa] @fail_to_canonicalize_init_enum_data_addr_reach_entry : $@convention(thin) (@inout Int32, Builtin.Int32, Builtin.Int1) -> Int32 {
229229
bb0(%0 : $*Int32, %1 : $Builtin.Int32, %2 : $Builtin.Int1):
230230
%s1 = alloc_stack $Optional<Int32>
@@ -255,10 +255,10 @@ bb2: // Preds: bb0 bb1
255255
}
256256

257257
// CHECK-LABEL: sil [ossa] @fail_to_canonicalize_init_enum_data_addr
258-
// XHECK: init_enum_data_addr
259-
// XHECK: inject_enum_addr
260-
// XHECK-NOT: enum $Optional<Int32>, #Optional.some!enumelt
261-
// XHECK: return
258+
// CHECK: init_enum_data_addr
259+
// CHECK: inject_enum_addr
260+
// CHECK-NOT: enum $Optional<Int32>, #Optional.some!enumelt
261+
// CHECK: return
262262
sil [ossa] @fail_to_canonicalize_init_enum_data_addr : $@convention(thin) (@inout Int32, Builtin.Int32) -> Int32 {
263263
bb0(%0 : $*Int32, %1 : $Builtin.Int32):
264264
%s1 = alloc_stack $Optional<Int32>
@@ -455,13 +455,13 @@ bb3(%14 : @owned $C):
455455
}
456456

457457
// CHECK-LABEL: sil [ossa] @test_inject_tuple
458-
// XHECK: [[A:%[0-9]+]] = alloc_stack $Optional<(Int, Int)>
459-
// XHECK: [[T:%[0-9]+]] = tuple (%0 : $Int, %1 : $Int)
460-
// XHECK: [[E:%[0-9]+]] = enum $Optional<(Int, Int)>, #Optional.some!enumelt, [[T]] : $(Int, Int)
461-
// XHECK: store [[E]] to [trivial] [[A]]
462-
// XHECK: [[L:%[0-9]+]] = load [trivial] [[A]]
463-
// XHECK: return [[L]]
464-
// XHECK: } // end sil function 'test_inject_tuple'
458+
// CHECK: [[A:%[0-9]+]] = alloc_stack $Optional<(Int, Int)>
459+
// CHECK: [[T:%[0-9]+]] = tuple (%0 : $Int, %1 : $Int)
460+
// CHECK: [[E:%[0-9]+]] = enum $Optional<(Int, Int)>, #Optional.some!enumelt, [[T]] : $(Int, Int)
461+
// CHECK: store [[E]] to [trivial] [[A]]
462+
// CHECK: [[L:%[0-9]+]] = load [trivial] [[A]]
463+
// CHECK: return [[L]]
464+
// CHECK: } // end sil function 'test_inject_tuple'
465465
sil [ossa] @test_inject_tuple : $@convention(thin) (Int, Int) -> Optional<(Int, Int)> {
466466
bb0(%0 : $Int, %1 : $Int):
467467
%17 = alloc_stack $Optional<(Int, Int)>
@@ -486,14 +486,14 @@ sil [ossa] @take_t : $@convention(thin) (@in T) -> ()
486486
sil [ossa] @use_mp : $@convention(thin) (@in_guaranteed MP) -> ()
487487

488488
// CHECK-LABEL: sil [ossa] @expand_alloc_stack_of_enum1
489-
// XHECK: [[A:%[0-9]+]] = alloc_stack $S
490-
// XHECK: bb1:
491-
// XHECK-NEXT: store %0 to [trivial] [[A]]
492-
// XHECK: bb2:
493-
// XHECK-NEXT: store %0 to [trivial] [[A]]
494-
// XHECK: bb3:
495-
// XHECK: apply {{%[0-9]+}}([[A]])
496-
// XHECK: } // end sil function 'expand_alloc_stack_of_enum1'
489+
// CHECK: [[A:%[0-9]+]] = alloc_stack $S
490+
// CHECK: bb1:
491+
// CHECK-NEXT: store %0 to [trivial] [[A]]
492+
// CHECK: bb2:
493+
// CHECK-NEXT: store %0 to [trivial] [[A]]
494+
// CHECK: bb3:
495+
// CHECK: apply {{%[0-9]+}}([[A]])
496+
// CHECK: } // end sil function 'expand_alloc_stack_of_enum1'
497497
sil [ossa] @expand_alloc_stack_of_enum1 : $@convention(method) (S) -> () {
498498
bb0(%0 : $S):
499499
%1 = alloc_stack $MP
@@ -521,14 +521,14 @@ bb3:
521521
}
522522

523523
// CHECK-LABEL: sil [ossa] @expand_alloc_stack_of_enum_without_take
524-
// XHECK: [[A:%[0-9]+]] = alloc_stack $S
525-
// XHECK: bb1:
526-
// XHECK-NEXT: store %0 to [trivial] [[A]]
527-
// XHECK: bb2:
528-
// XHECK-NEXT: store %0 to [trivial] [[A]]
529-
// XHECK: bb3:
530-
// XHECK: destroy_addr [[A]]
531-
// XHECK: } // end sil function 'expand_alloc_stack_of_enum_without_take'
524+
// CHECK: [[A:%[0-9]+]] = alloc_stack $S
525+
// CHECK: bb1:
526+
// CHECK-NEXT: store %0 to [trivial] [[A]]
527+
// CHECK: bb2:
528+
// CHECK-NEXT: store %0 to [trivial] [[A]]
529+
// CHECK: bb3:
530+
// CHECK: destroy_addr [[A]]
531+
// CHECK: } // end sil function 'expand_alloc_stack_of_enum_without_take'
532532
sil [ossa] @expand_alloc_stack_of_enum_without_take : $@convention(method) (S) -> () {
533533
bb0(%0 : $S):
534534
%1 = alloc_stack $MP
@@ -554,15 +554,15 @@ bb3:
554554
}
555555

556556
// CHECK-LABEL: sil [ossa] @expand_alloc_stack_of_enum_multiple_cases
557-
// XHECK: [[A:%[0-9]+]] = alloc_stack $T
558-
// XHECK: bb1:
559-
// XHECK-NEXT: [[COPY_ARG:%.*]] = copy_value %0
560-
// XHECK-NEXT: store [[COPY_ARG]] to [init] [[A]]
561-
// XHECK: apply {{%[0-9]+}}([[A]])
562-
// XHECK: bb2:
563-
// XHECK-NEXT: br bb3
564-
// XHECK: bb3:
565-
// XHECK: } // end sil function 'expand_alloc_stack_of_enum_multiple_cases'
557+
// CHECK: [[A:%[0-9]+]] = alloc_stack $T
558+
// CHECK: bb1:
559+
// CHECK-NEXT: [[COPY_ARG:%.*]] = copy_value %0
560+
// CHECK-NEXT: store [[COPY_ARG]] to [init] [[A]]
561+
// CHECK: apply {{%[0-9]+}}([[A]])
562+
// CHECK: bb2:
563+
// CHECK-NEXT: br bb3
564+
// CHECK: bb3:
565+
// CHECK: } // end sil function 'expand_alloc_stack_of_enum_multiple_cases'
566566
sil [ossa] @expand_alloc_stack_of_enum_multiple_cases : $@convention(method) (@guaranteed T) -> () {
567567
bb0(%0 : @guaranteed $T):
568568
%1 = alloc_stack $X
@@ -590,8 +590,8 @@ bb3:
590590
}
591591

592592
// CHECK-LABEL: sil [ossa] @dont_expand_alloc_stack_of_enum_multiple_cases
593-
// XHECK: alloc_stack $MP
594-
// XHECK: } // end sil function 'dont_expand_alloc_stack_of_enum_multiple_cases'
593+
// CHECK: alloc_stack $MP
594+
// CHECK: } // end sil function 'dont_expand_alloc_stack_of_enum_multiple_cases'
595595
sil [ossa] @dont_expand_alloc_stack_of_enum_multiple_cases : $@convention(method) (S) -> () {
596596
bb0(%0 : $S):
597597
%1 = alloc_stack $MP
@@ -617,8 +617,8 @@ bb3:
617617
}
618618

619619
// CHECK-LABEL: sil [ossa] @dont_expand_alloc_stack_of_enum_multiple_cases2
620-
// XHECK: alloc_stack $X
621-
// XHECK: } // end sil function 'dont_expand_alloc_stack_of_enum_multiple_cases2'
620+
// CHECK: alloc_stack $X
621+
// CHECK: } // end sil function 'dont_expand_alloc_stack_of_enum_multiple_cases2'
622622
sil [ossa] @dont_expand_alloc_stack_of_enum_multiple_cases2 : $@convention(method) (@guaranteed T) -> () {
623623
bb0(%0 : @guaranteed $T):
624624
%1 = alloc_stack $X
@@ -643,8 +643,8 @@ bb3:
643643
}
644644

645645
// CHECK-LABEL: sil [ossa] @dont_expand_alloc_stack_of_enum_unknown_use
646-
// XHECK: alloc_stack $MP
647-
// XHECK: } // end sil function 'dont_expand_alloc_stack_of_enum_unknown_use'
646+
// CHECK: alloc_stack $MP
647+
// CHECK: } // end sil function 'dont_expand_alloc_stack_of_enum_unknown_use'
648648
sil [ossa] @dont_expand_alloc_stack_of_enum_unknown_use : $@convention(method) (S) -> () {
649649
bb0(%0 : $S):
650650
%1 = alloc_stack $MP

0 commit comments

Comments
 (0)