Skip to content

std: use ptr.offset where possible in the vec iterator. - #8225

Closed
huonw wants to merge 2 commits into
rust-lang:masterfrom
huonw:vec-iter
Closed

std: use ptr.offset where possible in the vec iterator.#8225
huonw wants to merge 2 commits into
rust-lang:masterfrom
huonw:vec-iter

Conversation

@huonw

@huonwhuonw commented Aug 2, 2013

Copy link
Copy Markdown
Contributor

Closes#8212.

Before:

%sum.028 = phii64 [ %23, %match_else ], [ 0, %"normal return" ]
%.sroa.0.027 = phii64* [ %21, %match_else ], [ %12, %"normal return" ]
%19 = ptrtointi64*%.sroa.0.027toi64%20 = addi64%19, 8%21 = inttoptri64%20toi64*%22 = loadi64*%.sroa.0.027, align8%23 = addi64%22, %sum.028%24 = inttoptri64%20to %"enum.std::libc::types::common::c95::c_void[#1]"*
%25 = icmpeq %"enum.std::libc::types::common::c95::c_void[#1]"* %24, %16%26 = icmpeqi64%20, 0%or.cond = ori1%25, %26
test vec::bench::iterator ... bench: 87 ns/iter (+/- 7)
test vec::bench::mut_iterator ... bench: 87 ns/iter (+/- 10)

After:

%sum.028 = phii64 [ %21, %match_else ], [ 0, %"normal return" ]
%.sroa.0.027 = phii64* [ %19, %match_else ], [ %12, %"normal return" ]
%19 = getelementptri64*%.sroa.0.027, i641%20 = loadi64*%.sroa.0.027, align8%21 = addi64%20, %sum.028%22 = bitcasti64*%19to %"enum.std::libc::types::common::c95::c_void[#1]"*
%23 = icmpeq %"enum.std::libc::types::common::c95::c_void[#1]"* %22, %16%24 = icmpeqi64*%19, null%or.cond = ori1%23, %24
test vec::bench::iterator ... bench: 79 ns/iter (+/- 8)
test vec::bench::mut_iterator ... bench: 78 ns/iter (+/- 2)

(NB. I'm not 100% sure the benchmarks were set-up correctly, so take them with a grain of salt.)

@huonw

huonw commented Aug 2, 2013

Copy link
Copy Markdown
ContributorAuthor

r? @thestinger

@thestinger

Copy link
Copy Markdown
Contributor

\o/

bors added a commit that referenced this pull request Aug 2, 2013
Closes#8212.
Before:
```llvm
%sum.028 = phi i64 [ %23, %match_else ], [ 0, %"normal return" ]
%.sroa.0.027 = phi i64* [ %21, %match_else ], [ %12, %"normal return" ]
%19 = ptrtoint i64* %.sroa.0.027 to i64
%20 = add i64 %19, 8
%21 = inttoptr i64 %20 to i64*
%22 = load i64* %.sroa.0.027, align 8
%23 = add i64 %22, %sum.028
%24 = inttoptr i64 %20 to %"enum.std::libc::types::common::c95::c_void[#1]"*
%25 = icmp eq %"enum.std::libc::types::common::c95::c_void[#1]"* %24, %16
%26 = icmp eq i64 %20, 0
%or.cond = or i1 %25, %26
```
```
test vec::bench::iterator ... bench: 87 ns/iter (+/- 7)
test vec::bench::mut_iterator ... bench: 87 ns/iter (+/- 10)
```
After:
```llvm
%sum.028 = phi i64 [ %21, %match_else ], [ 0, %"normal return" ]
%.sroa.0.027 = phi i64* [ %19, %match_else ], [ %12, %"normal return" ]
%19 = getelementptr i64* %.sroa.0.027, i64 1
%20 = load i64* %.sroa.0.027, align 8
%21 = add i64 %20, %sum.028
%22 = bitcast i64* %19 to %"enum.std::libc::types::common::c95::c_void[#1]"*
%23 = icmp eq %"enum.std::libc::types::common::c95::c_void[#1]"* %22, %16
%24 = icmp eq i64* %19, null
%or.cond = or i1 %23, %24
```
```
test vec::bench::iterator ... bench: 79 ns/iter (+/- 8)
test vec::bench::mut_iterator ... bench: 78 ns/iter (+/- 2)
```
(NB. I'm not 100% sure the benchmarks were set-up correctly, so take them with a grain of salt.)
@thestinger

Copy link
Copy Markdown
Contributor

@huonw: it's fine if the benchmark doesn't show a statistically significant improvement, because I didn't expect any improvement in iteration speed alone - just when combined with other things (it can now optimize iterators to a memset/memcpy with loop-idiom, vectorize them with loop-vectorize and so on).

@huonw

huonw commented Aug 3, 2013

Copy link
Copy Markdown
ContributorAuthor

@thestinger yes, it was just a warning to anyone that this shouldn't be trumpeted as a 10% speed-up without further investigation.

@thestinger

Copy link
Copy Markdown
Contributor

Landing with #8257.

@huonw
huonw deleted the vec-iter branch December 4, 2014 02:02
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 13, 2022
…5, r=giraffate
fix `iter_not_returning_iterator`
fixesrust-lang#8225
changelog: Handle type projections in `iter_not_returning_iterator`
changelog: Don't lint `iter_not_returning_iterator` in trait implementations
changelog: Lint `iter_not_returning_iterator` in trait definitions
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Feb 11, 2024
…agnostic, r=Veykril
feat: Add incorrect case diagnostics for traits and their associated items
Updates incorrect case diagnostic to:
- Check traits and their associated items
- Ignore trait implementations except for patterns in associated function bodies
Also cleans up `hir-ty::diagnostics::decl_check` a bit (mostly to make it a bit more DRY and easier to maintain)
Also fixes: rust-lang#8675 and fixes: rust-lang#8225
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make the vector iterator use GEP, not ptrtoint + add + inttoptr

2 participants

@huonw@thestinger