Files
swift-mirror/test/IRGen/cold_split.swift
Kavon Farvardin 1c3ef6c51d ColdSplit: avoid with -Osize
Based on prior evaluation, this optimization always increases code
size. It splits out blocks and introduces calls, which always adds
extra instructions to shuffle values for calling conventions and
to make the actual call/return. Apple clang avoids the optimization
in `-Oz`, which I think is pretty close to what Swift's `-Osize`
really means.
2024-08-25 13:56:58 -07:00

43 lines
1.3 KiB
Swift

// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
// RUN: -enable-throws-prediction -O -enable-split-cold-code \
// RUN: | %FileCheck --check-prefix CHECK-ENABLED %s
//// Test disabling just the pass doesn't yield a split.
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
// RUN: -enable-throws-prediction -O -disable-split-cold-code \
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
//// Test using -Osize doesn't yield a split.
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
// RUN: -enable-throws-prediction -Osize -enable-split-cold-code \
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
//// Test disabling optimization entirely doesn't yield a split.
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
// RUN: -enable-throws-prediction -enable-split-cold-code \
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
// CHECK-ENABLED: cold
// CHECK-DISABLED-NOT: cold
enum MyError: Error { case err }
func getRandom(_ b: Bool) throws -> Int {
if b {
return Int.random(in: 0..<1024)
} else {
throw MyError.err
}
}
public func numberWithLogging(_ b: Bool) -> Int {
do {
return try getRandom(b)
} catch {
print("Log: random number generator failed with b=\(b)")
return 1337
}
}