Skip to content

[benchmark] Delete two benchmarks and add generic floating-point conversion lit tests #33853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 4 additions & 32 deletions benchmark/single-source/FloatingPointConversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@
import TestsUtils

public let FloatingPointConversion = [
BenchmarkInfo(
name: "ConvertFloatingPoint.ConcreteDoubleToDouble",
runFunction: run_ConvertFloatingPoint_ConcreteDoubleToDouble,
tags: [.validation, .api],
setUpFunction: { blackHole(doubles) }),
BenchmarkInfo(
name: "ConvertFloatingPoint.GenericDoubleToDouble",
runFunction: run_ConvertFloatingPoint_GenericDoubleToDouble,
tags: [.validation, .api],
setUpFunction: { blackHole(doubles) }),
BenchmarkInfo(
name: "ConvertFloatingPoint.MockFloat64ToDouble",
runFunction: run_ConvertFloatingPoint_MockFloat64ToDouble,
Expand Down Expand Up @@ -61,9 +51,9 @@ extension MockBinaryFloatingPoint {
init(_ value: Int) { self.init(_Value(value)) }
init(_ value: Float) { self.init(_Value(value)) }
init(_ value: Double) { self.init(_Value(value)) }
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
init(_ value: Float80) { self.init(_Value(value)) }
#endif
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
init(_ value: Float80) { self.init(_Value(value)) }
#endif
init(integerLiteral value: _Value.IntegerLiteralType) {
self.init(_Value(integerLiteral: value))
}
Expand Down Expand Up @@ -159,25 +149,7 @@ func convert<
U(value)
}

@inline(never)
public func run_ConvertFloatingPoint_ConcreteDoubleToDouble(_ N: Int) {
for _ in 0..<(N * 100) {
for element in doubles {
let f = Double(identity(element))
blackHole(f)
}
}
}

@inline(never)
public func run_ConvertFloatingPoint_GenericDoubleToDouble(_ N: Int) {
for _ in 0..<(N * 100) {
for element in doubles {
let f = convert(identity(element), to: Double.self)
blackHole(f)
}
}
}
// See also: test/SILOptimizer/floating_point_conversion.swift

@inline(never)
public func run_ConvertFloatingPoint_MockFloat64ToDouble(_ N: Int) {
Expand Down
34 changes: 28 additions & 6 deletions test/SILOptimizer/floating_point_conversion.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
// RUN: %target-swift-frontend -O -module-name=test -emit-sil %s | %FileCheck %s

func convert<
T: BinaryFloatingPoint, U: BinaryFloatingPoint
>(_ value: T, to: U.Type) -> U {
U(value)
T: BinaryFloatingPoint, U: BinaryFloatingPoint
>(_ value: T, to: U.Type) -> U {
U(value)
}

// Check that the follwing functions can be optimized to no-ops.
// Check that the following functions can be optimized to concrete conversions.

// CHECK-LABEL: sil @$s4test0A13DoubleToFloatySfSdF
// CHECK: bb0(%0 : $Double):
// CHECK: struct_extract %0 : $Double, #Double._value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual way to check this is to use patterns for the values, e.g.

[[ARG:%[0-9]+]] = struct_extract %0
[[CONV:%[0-9]+]] = builtin "fptrunc_FPIEEE64_FPIEEE32"([[ARG]])
...

But doing it with CHECK-NEXT is perfectly fine for this test.

// CHECK-NEXT: builtin "fptrunc_FPIEEE64_FPIEEE32"
// CHECK-NEXT: struct $Float
// CHECK-NEXT: return
// CHECK-NEXT: } // end sil function '$s4test0A13DoubleToFloatySfSdF'
public func testDoubleToFloat(_ x: Double) -> Float {
return convert(x, to: Float.self)
}

// CHECK-LABEL: sil @$s4test0A13FloatToDoubleySdSfF
// CHECK: bb0(%0 : $Float):
// CHECK: struct_extract %0 : $Float, #Float._value
// CHECK-NEXT: builtin "fpext_FPIEEE32_FPIEEE64"
// CHECK-NEXT: struct $Double
// CHECK-NEXT: return
// CHECK-NEXT: } // end sil function '$s4test0A13FloatToDoubleySdSfF'
public func testFloatToDouble(_ x: Float) -> Double {
return convert(x, to: Double.self)
}

// Check that the following functions can be optimized to no-ops.

// CHECK-LABEL: sil @$s4test0A6DoubleyS2dF
// CHECK: return %0
Expand All @@ -21,5 +45,3 @@ public func testDouble(_ x: Double) -> Double {
public func testFloat(_ x: Float) -> Float {
return convert(x, to: Float.self)
}