Skip to content

Commit 324ba39

Browse files
authored
Merge pull request #33853 from xwu/benchmark-to-lit-test
[benchmark] Delete two benchmarks and add generic floating-point conversion lit tests
2 parents 56f1a55 + 6a85fa7 commit 324ba39

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

benchmark/single-source/FloatingPointConversion.swift

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313
import TestsUtils
1414

1515
public let FloatingPointConversion = [
16-
BenchmarkInfo(
17-
name: "ConvertFloatingPoint.ConcreteDoubleToDouble",
18-
runFunction: run_ConvertFloatingPoint_ConcreteDoubleToDouble,
19-
tags: [.validation, .api],
20-
setUpFunction: { blackHole(doubles) }),
21-
BenchmarkInfo(
22-
name: "ConvertFloatingPoint.GenericDoubleToDouble",
23-
runFunction: run_ConvertFloatingPoint_GenericDoubleToDouble,
24-
tags: [.validation, .api],
25-
setUpFunction: { blackHole(doubles) }),
2616
BenchmarkInfo(
2717
name: "ConvertFloatingPoint.MockFloat64ToDouble",
2818
runFunction: run_ConvertFloatingPoint_MockFloat64ToDouble,
@@ -61,9 +51,9 @@ extension MockBinaryFloatingPoint {
6151
init(_ value: Int) { self.init(_Value(value)) }
6252
init(_ value: Float) { self.init(_Value(value)) }
6353
init(_ value: Double) { self.init(_Value(value)) }
64-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
65-
init(_ value: Float80) { self.init(_Value(value)) }
66-
#endif
54+
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
55+
init(_ value: Float80) { self.init(_Value(value)) }
56+
#endif
6757
init(integerLiteral value: _Value.IntegerLiteralType) {
6858
self.init(_Value(integerLiteral: value))
6959
}
@@ -159,25 +149,7 @@ func convert<
159149
U(value)
160150
}
161151

162-
@inline(never)
163-
public func run_ConvertFloatingPoint_ConcreteDoubleToDouble(_ N: Int) {
164-
for _ in 0..<(N * 100) {
165-
for element in doubles {
166-
let f = Double(identity(element))
167-
blackHole(f)
168-
}
169-
}
170-
}
171-
172-
@inline(never)
173-
public func run_ConvertFloatingPoint_GenericDoubleToDouble(_ N: Int) {
174-
for _ in 0..<(N * 100) {
175-
for element in doubles {
176-
let f = convert(identity(element), to: Double.self)
177-
blackHole(f)
178-
}
179-
}
180-
}
152+
// See also: test/SILOptimizer/floating_point_conversion.swift
181153

182154
@inline(never)
183155
public func run_ConvertFloatingPoint_MockFloat64ToDouble(_ N: Int) {

test/SILOptimizer/floating_point_conversion.swift

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
// RUN: %target-swift-frontend -O -module-name=test -emit-sil %s | %FileCheck %s
22

33
func convert<
4-
T: BinaryFloatingPoint, U: BinaryFloatingPoint
5-
>(_ value: T, to: U.Type) -> U {
6-
U(value)
4+
T: BinaryFloatingPoint, U: BinaryFloatingPoint
5+
>(_ value: T, to: U.Type) -> U {
6+
U(value)
77
}
88

9-
// Check that the follwing functions can be optimized to no-ops.
9+
// Check that the following functions can be optimized to concrete conversions.
10+
11+
// CHECK-LABEL: sil @$s4test0A13DoubleToFloatySfSdF
12+
// CHECK: bb0(%0 : $Double):
13+
// CHECK: struct_extract %0 : $Double, #Double._value
14+
// CHECK-NEXT: builtin "fptrunc_FPIEEE64_FPIEEE32"
15+
// CHECK-NEXT: struct $Float
16+
// CHECK-NEXT: return
17+
// CHECK-NEXT: } // end sil function '$s4test0A13DoubleToFloatySfSdF'
18+
public func testDoubleToFloat(_ x: Double) -> Float {
19+
return convert(x, to: Float.self)
20+
}
21+
22+
// CHECK-LABEL: sil @$s4test0A13FloatToDoubleySdSfF
23+
// CHECK: bb0(%0 : $Float):
24+
// CHECK: struct_extract %0 : $Float, #Float._value
25+
// CHECK-NEXT: builtin "fpext_FPIEEE32_FPIEEE64"
26+
// CHECK-NEXT: struct $Double
27+
// CHECK-NEXT: return
28+
// CHECK-NEXT: } // end sil function '$s4test0A13FloatToDoubleySdSfF'
29+
public func testFloatToDouble(_ x: Float) -> Double {
30+
return convert(x, to: Double.self)
31+
}
32+
33+
// Check that the following functions can be optimized to no-ops.
1034

1135
// CHECK-LABEL: sil @$s4test0A6DoubleyS2dF
1236
// CHECK: return %0
@@ -21,5 +45,3 @@ public func testDouble(_ x: Double) -> Double {
2145
public func testFloat(_ x: Float) -> Float {
2246
return convert(x, to: Float.self)
2347
}
24-
25-

0 commit comments

Comments
 (0)