-
Notifications
You must be signed in to change notification settings - Fork 1
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
Rock. Paper. blackHole(_:)
#69
Comments
Got a bit excited about this, but it seldom differentiates UInt192 and UInt256. Sad. @_optimize(none) @inline(never) @discardableResult func blackHole(_ x: @autoclosure () -> some Any) -> some Any { x() } |
That moment when you realize you have spent an hour trying various combinations of: @inline(never)
@_optimize(none)
@discardableResult
@_semantics("optimize.no.crossmodule")
public func blackHole<T>(_ x: T) { }
public func blackHole<T>(_ x: T) { _ = x }
public func blackHole<T>(_ x: T) -> T { x }
public func blackHole<T>(_ x: @autoclosure () -> T) { _ = x() }
public func blackHole<T>(_ x: @autoclosure () -> T) -> T { x() } |
With |
/.../TestsUtils.swift uses this function: @inline(never)
@_semantics("optimize.no.crossmodule")
public func blackHole<T>(_ x: T) { } |
Hm. So far, I've only tried using the @inline(never)
@_semantics("optimize.no.crossmodule")
@inlinable public func identity<T>(_ x: T) -> T { x } |
Well, I remain skeptical. But at least they are no longer reduced to nothing. |
I wonder if I also need to trick the compiler into thinking that constants could change between loops. Maybe it knows enough to copy-paste some initial computation into the black hole? 💭 |
I inserted fake mutations because if I can do it, the compiler can do it (probably). |
I'm not sure how I would measure |
I want to optimize some things, and need a way of telling the compiler to not erase my benchmarks. I mean, the current setup can identify some qualities, like whether the compiler can optimize it at all, but not much beyond that when it does. I have tried using the following function, but I saw no change in behavior.
The text was updated successfully, but these errors were encountered: