about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-21 08:55:13 +0000
committerbors <bors@rust-lang.org>2018-06-21 08:55:13 +0000
commit95979dcfb201f1d6906a2f256e5e311513cab4ea (patch)
tree66185002624f721557cd2b7781f1452d383fe74a /src/rustllvm/PassWrapper.cpp
parentfff1abadd7a4ec861ca4b9c77035379578ef033d (diff)
parent000aff604e3b16ffc3771bd5d93a6e7b425852d2 (diff)
downloadrust-95979dcfb201f1d6906a2f256e5e311513cab4ea.tar.gz
rust-95979dcfb201f1d6906a2f256e5e311513cab4ea.zip
Auto merge of #51601 - Emerentius:step_by_range_diet, r=sfackler
Specialize StepBy<Range(Inclusive)>

Part of #51557, related to #43064, #31155

As discussed in the above issues, `step_by` optimizes very badly on ranges which is related to
1. the special casing of the first `StepBy::next()` call
2. the need to do 2 additions of `n - 1` and `1` inside the range's `next()`

This PR eliminates both by overriding `next()` to always produce the current element and also step ahead by `n` elements in one go. The generated code is much better, even identical in the case of a `Range` with constant `start` and `end` where `start+step` can't overflow. Without constant bounds it's a bit longer than the manual loop. `RangeInclusive` doesn't optimize as nicely but is still much better than the original asm.
Unsigned integers optimize better than signed ones for some reason.

See the following two links for a comparison.

[godbolt: specialization for ..](https://godbolt.org/g/haHLJr)
[godbolt: specialization for ..=](https://godbolt.org/g/ewyMu6)

`RangeFrom`, the only other range with an `Iterator` implementation can't be specialized like this without changing behaviour due to overflow. There is no way to save "finished-ness".

The approach can not be used in general, because it would produce side effects of the underlying iterator too early.

May obsolete #51435, haven't checked.
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions