File tree 3 files changed +38
-1
lines changed
SwiftCompilerSources/Sources/Optimizer
InstructionSimplification
3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -277,7 +277,7 @@ private extension AllocStackInst {
277
277
// The instruction which defines the existential archetype must dominate the alloc_stack, because
278
278
// after the transformation the alloc_stack will use the existential archetype.
279
279
for openArchetypeOp in initExistential. typeDependentOperands {
280
- if !openArchetypeOp. value. definingInstruction! . dominatesInSameBlock ( self ) {
280
+ if !openArchetypeOp. value. triviallyDominates ( self ) {
281
281
return nil
282
282
}
283
283
}
Original file line number Diff line number Diff line change @@ -185,6 +185,24 @@ extension Value {
185
185
}
186
186
return true
187
187
}
188
+
189
+ /// Performs a simple dominance check without using the dominator tree.
190
+ /// Returns true if `instruction` is in the same block as this value, but "after" this value,
191
+ /// or if this value is a function argument.
192
+ func triviallyDominates( _ instruction: Instruction ) -> Bool {
193
+ switch self {
194
+ case is FunctionArgument :
195
+ return true
196
+ case let arg as Argument :
197
+ return arg. parentBlock == instruction. parentBlock
198
+ case let svi as SingleValueInstruction :
199
+ return svi. dominatesInSameBlock ( instruction)
200
+ case let mvi as MultipleValueInstructionResult :
201
+ return mvi. parentInstruction. dominatesInSameBlock ( instruction)
202
+ default :
203
+ return false
204
+ }
205
+ }
188
206
}
189
207
190
208
extension FullApplySite {
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ public struct S {}
10
10
protocol P {
11
11
}
12
12
13
+ public class C2: P {}
14
+
13
15
public struct T: P {
14
16
let c: C
15
17
let s: S
@@ -36,6 +38,7 @@ public enum X {
36
38
sil [ossa] @take_s : $@convention(thin) (@in S) -> ()
37
39
sil [ossa] @take_t : $@convention(thin) (@in T) -> ()
38
40
sil [ossa] @use_mp : $@convention(thin) (@in_guaranteed MP) -> ()
41
+ sil [ossa] @use_c2 : $@convention(thin) (@in_guaranteed C2) -> ()
39
42
40
43
// CHECK-LABEL: sil [ossa] @expand_alloc_stack_of_enum1 :
41
44
// CHECK: [[A:%[0-9]+]] = alloc_stack $S
@@ -346,3 +349,19 @@ bb3:
346
349
return %r
347
350
}
348
351
352
+ // CHECK-LABEL: sil [ossa] @init_existential_with_dynamic_self :
353
+ // CHECK: [[S:%.*]] = alloc_stack $C2
354
+ // CHECK: store %0 to [init] [[S]]
355
+ // CHECK: apply %{{[0-9]+}}([[S]])
356
+ // CHECK: } // end sil function 'init_existential_with_dynamic_self'
357
+ sil [ossa] @init_existential_with_dynamic_self : $@convention(method) (@owned C2) -> () {
358
+ bb0(%0 : @owned $C2):
359
+ %1 = alloc_stack $P
360
+ %2 = init_existential_addr %1, $@dynamic_self C2
361
+ store %0 to [init] %2
362
+ %4 = function_ref @use_c2 : $@convention(thin) (@in_guaranteed C2) -> ()
363
+ %5 = apply %4(%2) : $@convention(thin) (@in_guaranteed C2) -> ()
364
+ destroy_addr %1
365
+ dealloc_stack %1
366
+ return %5
367
+ }
You can’t perform that action at this time.
0 commit comments