Files
swift-mirror/test/SILOptimizer/dead_array_elim.swift
Ravi Kandhadai a6bed21d9e [SIL Optimization] Make ArraySemantics.cpp aware of "array.uninitialized_intrinsic"
semantics attribute that is used by the top-level array initializer (in ArrayShared.swift),
which is the entry point used by the compiler to initialize array from array literals.
This initializer is early-inlined so that other optimizations can work on its body.

Fix DeadObjectElimination and ArrayCOWOpts optimization passes to work with this
semantics attribute in addition to "array.uninitialized", which they already use.

Refactor mapInitializationStores function from ArrayElementValuePropagation.cpp to
ArraySemantic.cpp so that the array-initialization pattern matching functionality
implemented by the function can be reused by other optimizations.
2020-02-05 14:28:34 -08:00

41 lines
1.5 KiB
Swift

// RUN: %target-swift-frontend -O -emit-sil -primary-file %s | %FileCheck %s
// These tests check whether DeadObjectElimination pass runs as a part of the
// optimization pipeline and eliminates dead array literals in Swift code.
// Note that DeadObjectElimination pass relies on @_semantics annotations on
// the array initializer that is used by the compiler to create array literals.
// This test would fail if in case the initializer used by the compiler to
// initialize array literals doesn't match the one expected by the pass.
// CHECK-LABEL: sil hidden @$s15dead_array_elim24testDeadArrayEliminationyyF
func testDeadArrayElimination() {
_ = [1, 2, 3]
// CHECK: bb0:
// CHECK-NEXT: %{{.*}} = tuple ()
// CHECK-NEXT: return %{{.*}} : $()
}
// CHECK-LABEL: sil hidden @$s15dead_array_elim29testEmptyDeadArrayEliminationyyF
func testEmptyDeadArrayElimination() {
_ = []
// CHECK: bb0:
// CHECK-NEXT: %{{.*}} = tuple ()
// CHECK-NEXT: return %{{.*}} : $()
}
// The use case tested by the following test, where a _fixLifetime call is
// invoked on an array, appears when new os log APIs are used.
// CHECK-LABEL: sil hidden @$s15dead_array_elim35testDeadArrayElimWithFixLifetimeUseyyF
func testDeadArrayElimWithFixLifetimeUse() {
let a: [Int] = []
_fixLifetime(a)
// CHECK: bb0:
// CHECK-NEXT: %{{.*}} = tuple ()
// CHECK-NEXT: return %{{.*}} : $()
}
// FIXME: DeadObjectElimination doesn't optimize this yet.
func testDeadArrayElimWithAddressOnlyValues<T>(x: T, y: T) {
_ = [x, y]
}