Skip to content

Conversation

@eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Jul 18, 2025

rdar://156345209

Copy link
Contributor

@stephentyrone stephentyrone Jul 18, 2025

Choose a reason for hiding this comment

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

I'm fine with taking this as is, but we should talk to LLVM about whether they'd prefer we use range metadata or llvm.assume for these going forward, and then make both paths use the one they want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on benchmark results, the best is to keep the range-metadata if possible.

@stephentyrone
Copy link
Contributor

@swift-ci test

stephentyrone added a commit that referenced this pull request Jul 21, 2025
LLVM ought to be able to do this transformation for us, but it currently fails to do so. We can code around it easily enough. #83172 has a better long-term fix.
stephentyrone added a commit to stephentyrone/swift that referenced this pull request Jul 21, 2025
This allows us to eliminate a comparison; swiftlang#83172 will allow the compiler to do it for us instead in the future.
@stephentyrone
Copy link
Contributor

@eeckstein let's roll a revert of the [Mutable]Span changes from #83150 into this for the main branch.

So far we only supported this for `load` and `call` arguments. Now we use `llvm.assume` for other kind of argument values. This helps optimizing bounds checking for `Span`.
@eeckstein eeckstein force-pushed the span-bounds-checking branch from 451290d to 27dc031 Compare July 22, 2025 10:46
@eeckstein eeckstein marked this pull request as ready for review July 22, 2025 10:47
@eeckstein eeckstein requested a review from AnthonyLatsis as a code owner July 22, 2025 10:47
@eeckstein
Copy link
Contributor Author

@swift-ci apple silicon benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit 18b02a7 into swiftlang:main Jul 22, 2025
6 checks passed
@eeckstein eeckstein deleted the span-bounds-checking branch July 22, 2025 20:00
stephentyrone added a commit that referenced this pull request Jul 23, 2025
This allows us to eliminate a comparison; #83172 will allow the compiler to do it for us instead in the future. **Explanation:** Changes the implementation of Span's subscript bounds checks to use a single unsigned comparison instead of two signed compares. **Scope:** Narrow. Does not apply to any other API. **Issues:** rdar://156068535 **Original PRs:** #83150 **Risk:** Low. Minor implementation tweaks to API that is not widely adopted. **Testing:** CI **Reviewers:** @glessard @meg-gupta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants