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-9287] Poor codegen for String iteration #51759

Closed
milseman mannequin opened this issue Nov 16, 2018 · 2 comments
Closed

[SR-9287] Poor codegen for String iteration #51759

milseman mannequin opened this issue Nov 16, 2018 · 2 comments
Labels
standard library Area: Standard library umbrella

Comments

@milseman
Copy link
Mannequin

milseman mannequin commented Nov 16, 2018

Previous ID SR-9287
Radar None
Original Reporter @milseman
Type Sub-task
Status Resolved
Resolution Won't Do

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Sub-task
Assignee None
Priority Medium

md5: 3afd21a3d5c5fdb43a34542025636106

Parent-Task:

Issue Description:

Iterating the UnicodeScalarView generates some poor code, e.g. we spill the baseAddress pointer on each iteration, fail some LICM, and do not get a beneficial loop unswitch.

I do not believe in asking for general loop unswitching, which is often a pessimization. However, Swift's iterator design means that we are unable to manually unswitch iteration loops when we need to. So, we need some mechanism to communicate what path of an iteration loop should be unswitched, and branch-weight metadata doesn't do this for us in LLVM. This would dramatically decrease the register pressure on the fast path as well, so we wouldn't have to spill the pointer we're iterating over.

In the mean time, I'll try to hand-tune the code paths to compensate as much as possible.

Affected benchmark: StrComplexWalk

@milseman
Copy link
Mannequin Author

milseman mannequin commented Nov 16, 2018

In the attachment, we see

mov rax, qword [rbp+var_60]

, which is spilling the one register we don't want to spill here. This is all along the fast-path and LLVM branch-weight metadata is doing its job (red means fall-through), but it would also be far better to unswitch the loop, which should also alleviate register pressure.

@milseman
Copy link
Mannequin Author

milseman mannequin commented Dec 6, 2018

This is unlikely to be totally fixable in Swift in the near-term, but progress on https://bugs.swift.org/browse/SR-9424 would help greatly.

@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
standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

0 participants