-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #53080 - hermord:rc-opt, r=alexcrichton
Change `Rc::inc_{weak,strong}` to better hint optimization to LLVM As discussed in #13018, `Rc::inc_strong` and `Rc::inc_weak` are changed to allow compositions of `clone` and `drop` to be better optimized. Almost entirely as in [this comment](#13018 (comment)), except that `abort` on zero is added so that a `drop(t.clone())` does not produce a zero check followed by conditional deallocation. This is different from #21418 in that it doesn't rely on `assume`, avoiding the prohibitive compilation slowdown. [Before and after IR](https://gist.github.com/hermord/266e55451b7fe0bb8caa6e35d17c86e1).
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2018 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. | ||
|
||
// compile-flags: -O | ||
|
||
// A drop([...].clone()) sequence on an Rc should be a no-op | ||
// In particular, no call to __rust_dealloc should be emitted | ||
#![crate_type = "lib"] | ||
use std::rc::Rc; | ||
|
||
pub fn foo(t: &Rc<Vec<usize>>) { | ||
// CHECK-NOT: __rust_dealloc | ||
drop(t.clone()); | ||
} |