Skip to content
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

[SR-12054] Optimisation misses in n-body benchmark game #54490

Closed
troughton opened this issue Jan 20, 2020 · 2 comments
Closed

[SR-12054] Optimisation misses in n-body benchmark game #54490

troughton opened this issue Jan 20, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@troughton
Copy link
Contributor

Previous ID SR-12054
Radar rdar://problem/58997082
Original Reporter @troughton
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 731e1a7fdbe90e0a2521ffee436d04ed

Issue Description:

I was playing around with one of the benchmark game programs and ran into a few performance edge cases.

The first was that marking a method as public caused inlining behaviour to change even in `-wmo` mode. Compare the effects of marking `dot` as `public`:

https://godbolt.org/z/WPZtHx (internal) vs https://godbolt.org/z/QcurxC (public). When `dot` is marked as public, `addingProduct` does not get inlined.

The second issue I noticed was that calling `SIMD4<Double>.init(_ value: SIMD4<Double>)` causes a bunch of calls to:

(generic specialization <Swift.Double> of generic partial specialization <serialized, Signature = @escaping @convention(thin) @convention(method) <A><A1 where A == Swift.Double, A1: Swift.BinaryFloatingPoint> (@in_guaranteed A1, @unowned @thick Swift.Double.Type) -> (@out Swift.Double, @unowned Swift.Bool)> of static (extension in Swift):Swift.BinaryFloatingPoint._convert<A where A1: Swift.BinaryFloatingPoint>(from: A1) -> (value: A, exact: Swift.Bool))

even though it should be a no-op. This can easily be observed by e.g. changing line 57 from `let posi = bodyi.pos` to `let posi = Vec4(bodyi.pos)`.

The third is that changing `System` from a `struct` to a `class` (https://godbolt.org/z/tJSudD) increases execution time from 2.56 to 3.43 on my computer, when it should have no change on the behaviour.

The test case:

main.swift with compile flags `-Ounchecked -wmo -Xllvm -unroll-count=5 -Xllvm -unroll-threshold=500 -Xcc -march=native -Xcc -ffast-math -Xcc -mavx2`

This was all tested with Swift 5.2 dev, commit 2007515

@troughton
Copy link
Contributor Author

@stephentyrone The SIMD initialiser issue here is probably relevant to you.

@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants