Files
swift-mirror/test/Interop/C/struct/foreign-reference.swift
Erik Eckstein ba4081ee76 Optimizer: replace PredictableMemoryAccessOptimizations with MandatoryRedundantLoadElimination in the pass pipeline
PredictableMemoryAccessOptimizations has become unmaintainable as-is.
RedundantLoadElimination does (almost) the same thing as PredictableMemoryAccessOptimizations.
It's not as powerful but good enough because PredictableMemoryAccessOptimizations is actually only needed for promoting integer values for mandatory constant propagation.
And most importantly: RedundantLoadElimination does not insert additional copies which was a big problem in PredictableMemoryAccessOptimizations.

Fixes rdar://142814676
2025-02-07 11:30:35 +01:00

54 lines
1.3 KiB
Swift

// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -validate-tbd-against-ir=none -Xfrontend -experimental-c-foreign-reference-types -Onone -D NO_OPTIMIZATIONS)
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -validate-tbd-against-ir=none -Xfrontend -experimental-c-foreign-reference-types -O)
//
// REQUIRES: executable_test
// TODO: This should work without ObjC interop in the future rdar://97497120
// REQUIRES: objc_interop
import StdlibUnittest
import ForeignReference
var ReferenceCountedTestSuite = TestSuite("Foreign reference types that have reference counts")
@inline(never)
public func blackHole<T>(_ _: T) { }
ReferenceCountedTestSuite.test("Local") {
var x = createLocalCount()
#if NO_OPTIMIZATIONS
expectEqual(x.value, 2)
#endif
let t = (x, x, x)
#if NO_OPTIMIZATIONS
expectEqual(x.value, 5)
#endif
}
@inline(never)
func globalTest1() {
var x = createGlobalCount()
let t = (x, x, x)
#if NO_OPTIMIZATIONS
expectEqual(globalCount, 4)
#endif
blackHole(t)
}
@inline(never)
func globalTest2() {
var x = createGlobalCount()
#if NO_OPTIMIZATIONS
expectEqual(globalCount, 1)
#endif
}
ReferenceCountedTestSuite.test("Global") {
expectEqual(globalCount, 0)
globalTest1()
globalTest2()
expectEqual(globalCount, 0)
}
runAllTests()