Skip to content

Commit

Permalink
Rollup merge of rust-lang#43513 - alexcrichton:inline-repeat, r=Burnt…
Browse files Browse the repository at this point in the history
…Sushi

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

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

Closes rust-lang#43272
  • Loading branch information
Mark-Simulacrum authored Jul 30, 2017
2 parents 5b85f65 + 54b6b23 commit a3eadd7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/liballoc/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl Layout {
/// of each element in the array.
///
/// On arithmetic overflow, returns `None`.
#[inline]
pub fn repeat(&self, n: usize) -> Option<(Self, usize)> {
let padded_size = match self.size.checked_add(self.padding_needed_for(self.align)) {
None => return None,
Expand Down
21 changes: 21 additions & 0 deletions src/test/codegen/vec-optimizes-away.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// no-system-llvm
// compile-flags: -O
#![crate_type="lib"]

#[no_mangle]
pub fn sum_me() -> i32 {
// CHECK-LABEL: @sum_me
// CHECK-NEXT: {{^.*:$}}
// CHECK-NEXT: ret i32 6
vec![1, 2, 3].iter().sum::<i32>()
}

0 comments on commit a3eadd7

Please sign in to comment.