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

Trivial vec![] creation then iteration doesn't optimize out the allocation #43272

Closed
bluss opened this Issue Jul 16, 2017 · 6 comments

Comments

Projects
None yet
6 participants
@bluss
Copy link
Contributor

bluss commented Jul 16, 2017

Rustc used to be able to replace vec![1, 2, 3].iter().sum::<i32>() with a constant when optimizing, not at the moment. It simply looks like a Layout method that is not inlinable.

(This is a regression strictly speaking — stable & beta can do this optimization, but not nightly.)

Code to reproduce:

playground link

pub fn sum_me() -> i32 {
    vec![1, 2, 3].iter().sum::<i32>()
}
@nodakai

This comment has been minimized.

Copy link
Contributor

nodakai commented Jul 17, 2017

Are there any ways to write automated tests to check for "regressions" like this? Assertions against LLVM bitcode?

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Jul 17, 2017

@nodakai Yes codegen tests can be used for this, e.g. https://github.com/rust-lang/rust/blob/master/src/test/codegen/alloc-optimisation.rs. Assuming this is run against the bitcode after optimization, that is.

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented Jul 27, 2017

cc @arielb1 -- seems LLVM related

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 27, 2017

Nope. Just Layout::repeat (

pub fn repeat(&self, n: usize) -> Option<(Self, usize)> {
) that is not marked as inline.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 27, 2017

@arielb1 arielb1 added T-libs and removed T-compiler labels Jul 27, 2017

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 27, 2017

I didn't confirm that making Layout::repeat as inline fixes this, so please confirm that/add a test before closing.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 27, 2017

std: Mark `Layout::repeat` as `#[inline]`
This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 27, 2017

std: Mark `Layout::repeat` as `#[inline]`
This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 27, 2017

std: Mark `Layout::repeat` as `#[inline]`
This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272

frewsxcv added a commit to frewsxcv/rust that referenced this issue Jul 29, 2017

Rollup merge of rust-lang#43513 - alexcrichton:inline-repeat, r=Burnt…
…Sushi

std: Mark `Layout::repeat` as `#[inline]`

This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 29, 2017

std: Mark `Layout::repeat` as `#[inline]`
This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 29, 2017

std: Mark `Layout::repeat` as `#[inline]`
This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 30, 2017

Rollup merge of rust-lang#43513 - alexcrichton:inline-repeat, r=Burnt…
…Sushi

std: Mark `Layout::repeat` as `#[inline]`

This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272

@bors bors closed this in #43513 Jul 30, 2017

matthewhammer pushed a commit to matthewhammer/rust that referenced this issue Aug 3, 2017

std: Mark `Layout::repeat` as `#[inline]`
This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 12, 2017

std: Mark `Layout::repeat` as `#[inline]`
This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes rust-lang#43272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.