Files
swift-mirror/test/SILOptimizer/dead_alloc_stack.swift
Erik Eckstein 93d3226790 DeadObjectElimination: handle init_existential_addr instructions.
This allows to eliminate a dead stack location which contains an existential.

rdar://problem/32272199
2020-02-18 19:23:17 +01:00

32 lines
698 B
Swift

// RUN: %target-swift-frontend -O -emit-sil -parse-as-library %s | %FileCheck %s
protocol E {
func f() -> Bool
}
protocol P {
associatedtype A = Int
}
public struct X : P, E {
func f() -> Bool { return true }
}
func g<T : P>(_ x : T) -> Bool {
if let y = x as? E { return y.f() }
return false
}
// Check that this function can be completely constant folded and no alloc_stack remains.
// CHECK-LABEL: sil @$s16dead_alloc_stack6testitySbAA1XVF
// CHECK: bb0({{.*}}):
// CHECK-NEXT: integer_literal
// CHECK-NEXT: struct
// CHECK-NEXT: return
// CHECK-NEXT: } // end sil function '$s16dead_alloc_stack6testitySbAA1XVF'
public func testit(_ x: X) -> Bool {
return g(x)
}