Skip to content

Help LLVM better optimize slice::Iter(Mut)::len - #61885

Merged
bors merged 1 commit into
rust-lang:masterfrom
scottmcm:slice-iter-len-opt
Jun 18, 2019
Merged

Help LLVM better optimize slice::Iter(Mut)::len#61885
bors merged 1 commit into
rust-lang:masterfrom
scottmcm:slice-iter-len-opt

Conversation

@scottmcm

Copy link
Copy Markdown
Member

r? @RalfJung

I've included a codegen test that fails without this change as a demonstration of usefulness.

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 16, 2019
@rust-highfive

This comment has been minimized.

@scottmcm
scottmcmforce-pushed the slice-iter-len-opt branch from be3ca63 to af0e35eCompareJune 16, 2019 04:15
@hanna-kruppe

Copy link
Copy Markdown
Contributor

Nice! r=me unless you want more eyes on this first.

@RalfJung

Copy link
Copy Markdown
Member

Yes this looks great!

Do we have tests in src/liballoc that exhibit this? Would be nice to make sure Miri runs this code in a couple of situations, just to be sure.

@RalfJung

Copy link
Copy Markdown
Member

Oh also, should we see if this has any perf influence?

@RalfJung

Copy link
Copy Markdown
Member

Well let's get a try build.

@bors try

@bors

bors commented Jun 16, 2019

Copy link
Copy Markdown
Collaborator

⌛ Trying commit af0e35e with merge 9dd34620937c9854a002172599a6217be05f6520...

@bors

bors commented Jun 16, 2019

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-travis
Build commit: 9dd34620937c9854a002172599a6217be05f6520

@RalfJung

Copy link
Copy Markdown
Member

@rust-timer build 9dd34620937c9854a002172599a6217be05f6520

@rust-timer

Copy link
Copy Markdown
Collaborator

Success: Queued 9dd34620937c9854a002172599a6217be05f6520 with parent 6865502, comparison URL.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking try commit 9dd34620937c9854a002172599a6217be05f6520, comparison URL.

@scottmcm

scottmcm commented Jun 17, 2019

Copy link
Copy Markdown
MemberAuthor

Looks like just noise in the perf run, which doesn't surprise me. (Anyone using is_empty is unaffected by this, since it's overridden separately, and it's a tiny change anyway.)

Would be nice to make sure Miri runs this code in a couple of situations, just to be sure.

Hmm, looks like I get an

error[E0080]:Miri evaluation error: unimplemented intrinsic: unchecked_sub

on the playground. I guess I should make a MIRI PR before this goes in?

Edit: I should have looked, seems like you're already on it rust-lang/miri#776 ❤️

@RalfJung

Copy link
Copy Markdown
Member

I can't find any explicit tests for the slice iterator length method, but running miri-test-libstd on this PR shows that the code path does get hit, e.g. through slice::to_vec.

@RalfJung

Copy link
Copy Markdown
Member

Ah, and this macro also gets used in nth and position and try_fold and more, so I think we are good in terms of coverage.

@bors r=rkruppe,RalfJung

@bors

bors commented Jun 17, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit af0e35e has been approved by rkruppe,RalfJung

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2019
Centril added a commit to Centril/rust that referenced this pull request Jun 17, 2019
…ppe,RalfJung
Help LLVM better optimize slice::Iter(Mut)::len
r? @RalfJung
I've included a codegen test that fails without this change as a demonstration of usefulness.
@CentrilCentril mentioned this pull request Jun 17, 2019
bors added a commit that referenced this pull request Jun 17, 2019
Rollup of 5 pull requests
Successful merges:
- #61702 (test more variants of enum-int-casting)
- #61836 (Replace some uses of NodeId with HirId)
- #61885 (Help LLVM better optimize slice::Iter(Mut)::len)
- #61893 (make `Weak::ptr_eq`s into methods)
- #61908 (don't ICE on large files)
Failed merges:
r? @ghost
@bors
bors merged commit af0e35e into rust-lang:masterJun 18, 2019
@scottmcm
scottmcm deleted the slice-iter-len-opt branch June 18, 2019 03:47
@RalfJungRalfJung mentioned this pull request Jun 18, 2019
bors added a commit that referenced this pull request Jun 18, 2019
update miri
Tests fail since #61885, this should fix that.
r? @oli-obk
Comment threadsrc/libcore/slice/mod.rs
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2023
Simplify manual ptr arithmetic in slice::Iter with ptr_sub
The old code was introduced in rust-lang#61885, which predates the ptr_sub method and underlying intrinsic. The codegen test still passes.
r? `@scottmcm`
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@scottmcm@rust-highfive@hanna-kruppe@RalfJung@bors@rust-timer@vitiral