Files
swift-mirror/test/SILOptimizer/dead_array_elim.swift
Michael Gottesman 090a592896 Disable two tests on 32 bit until they are updated.
Unblocking the bots.
2021-03-02 11:15:06 -08:00

82 lines
3.0 KiB
Swift

// RUN: %target-swift-frontend -O -emit-sil -primary-file %s | %FileCheck %s
// REQUIRES: swift_stdlib_no_asserts
// XFAIL: OS=linux-androideabi
// Test needs to be updated for 32bit.
// rdar://74810823
// UNSUPPORTED: PTRSIZE=32
// 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.
// testDeadArrayElimination requires swift_stdlib_no_asserts because,
// with runtime verification enabled, "array.finalize" becomes a
// mutating operation, preventing SILCombine from deleting it when it
// removes dead pure instructions. After inlining,
// DeadObjectElimination is still unable to remove the array because a
// second array is initialized by copying the first. This problem can be
// overcome by handling non-trivial stores in OSSA, as described here:
// [OSSA] Improve DeadObjectElimination to handle array copies
// https://bugs.swift.org/browse/SR-13782
// Once that bug is fixed, remove the requirement: swift_stdlib_no_asserts.
// 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]
}
// CHECK-LABEL: sil hidden @$s15dead_array_elim31testDeadArrayAfterOptimizationsySiSSF
// CHECK: bb0(%0 : $String):
// CHECK-NEXT: debug_value {{.*}} name "stringParameter"
// CHECK-NEXT: integer_literal $Builtin.Int{{[0-9]+}}, 21
// CHECK-NEXT: struct $Int
// CHECK-NEXT: return
// CHECK: } // end sil function '$s15dead_array_elim31testDeadArrayAfterOptimizationsySiSSF'
func testDeadArrayAfterOptimizations(_ stringParameter: String) -> Int {
var sum = 0
for x in [(1, "hello"),
(2, "a larger string which does not fit into a small string"),
(3, stringParameter),
(4, "hello"),
(5, "hello"),
(6, "hello"),
] {
sum += x.0
}
return sum
}