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-203] Missed optimization opportunity (loop unrolling, SIMD) #42825

Closed
jepers opened this issue Dec 12, 2015 · 4 comments
Closed

[SR-203] Missed optimization opportunity (loop unrolling, SIMD) #42825

jepers opened this issue Dec 12, 2015 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@jepers
Copy link

jepers commented Dec 12, 2015

Previous ID SR-203
Radar None
Original Reporter @jepers
Type Bug
Status Closed
Resolution Done

Attachment: Download

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

md5: a3257dee833a6f8d992d3752f8dc6e04

Issue Description:

Swift's ability to produce highly optimized code from relatively high level abstractions is getting increasingly better, and the current open source master has improved hugely compared to Xcode 7.2 GM.

However, our (and supposedly many others') projects would benefit greatly from even further improvements in cases like the one exemplified by the attached stand-alone test program.

The test demonstrates how manually unrolling a simple for-loop (over a statically knowable int range) makes the code approximately 4 times faster (which is as fast as the SIMD equivalent of the custom type used).

I wish the optimizer could make sure this kind of manual unrolling wasn't necessary.

Filed this bug as requested here:
https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151207/000266.html

@aschwaighofer
Copy link
Member

This should be addressed when my work on unrolling goes in.

(https://github.com/aschwaighofer/swift/tree/loop_unrolling)

$ ./unroll-test
Running test compiled with manuallyUnrolled = true:
float4 median time: 0.001071 s (DCE-prevention: 20283)
V4<Float> median time: 0.001127 s (DCE-prevention: 59705)
float4x4 median time: 0.004334 s (DCE-prevention: 43784)
V4<V4<Float>> median time: 0.004346 s (DCE-prevention: 30778)

$ ./unroll-test
Running test compiled with manuallyUnrolled = false:
float4 median time: 0.001070 s (DCE-prevention: 27745)
V4<Float> median time: 0.001121 s (DCE-prevention: 41516)
float4x4 median time: 0.004331 s (DCE-prevention: 28166)
V4<V4<Float>> median time: 0.004340 s (DCE-prevention: 64316)

@jepers
Copy link
Author

jepers commented Dec 12, 2015

Wow, thanks!
I suppose it's not possible to say anything about ~ when these improvements will be included in an Xcode GM?

@aschwaighofer
Copy link
Member

This was fixed by
edf9ca0 Unroll loops with known short trip count

@jepers
Copy link
Author

jepers commented Jun 19, 2016

This fix seems to be missing in Swift 3 (Xcode 8.0 beta), or something else is making this test run 200 times slower with Swift 3 than with Swift 2.2. Please see: https://bugs.swift.org/browse/SR-1824

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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