Skip to content

Commit bdace29

Browse files
committed
Auto merge of #50744 - nikic:mutable-noalias, r=alexcrichton
Emit noalias on &mut parameters by default This used to be disabled due to LLVM bugs in the handling of noalias information in conjunction with unwinding. However, according to #31681 all known LLVM bugs have been fixed by LLVM 6.0, so it's probably time to reenable this optimization. -Z no-mutable-noalias is left as an escape-hatch to debug problems suspected to stem from this change.
2 parents 8319ef5 + 1230813 commit bdace29

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/librustc/session/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12391239
"print the result of the monomorphization collection pass"),
12401240
mir_opt_level: usize = (1, parse_uint, [TRACKED],
12411241
"set the MIR optimization level (0-3, default: 1)"),
1242-
mutable_noalias: bool = (false, parse_bool, [TRACKED],
1243-
"emit noalias metadata for mutable references"),
1242+
mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
1243+
"emit noalias metadata for mutable references (default: yes on LLVM >= 6)"),
12441244
arg_align_attributes: bool = (false, parse_bool, [TRACKED],
12451245
"emit align metadata for reference arguments"),
12461246
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],

src/librustc_codegen_llvm/type_of.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use abi::{FnType, FnTypeExt};
1212
use common::*;
13+
use llvm;
1314
use rustc::hir;
1415
use rustc::ty::{self, Ty, TypeFoldable};
1516
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
@@ -428,8 +429,13 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
428429
PointerKind::Shared
429430
},
430431
hir::MutMutable => {
431-
if cx.tcx.sess.opts.debugging_opts.mutable_noalias ||
432-
cx.tcx.sess.panic_strategy() == PanicStrategy::Abort {
432+
// Only emit noalias annotations for LLVM >= 6 or in panic=abort
433+
// mode, as prior versions had many bugs in conjunction with
434+
// unwinding. See also issue #31681.
435+
let mutable_noalias = cx.tcx.sess.opts.debugging_opts.mutable_noalias
436+
.unwrap_or(unsafe { llvm::LLVMRustVersionMajor() >= 6 }
437+
|| cx.tcx.sess.panic_strategy() == PanicStrategy::Abort);
438+
if mutable_noalias {
433439
PointerKind::UniqueBorrowed
434440
} else {
435441
PointerKind::Shared

src/test/codegen/function-arguments.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// compile-flags: -C no-prepopulate-passes
1212
// ignore-tidy-linelength
13+
// min-llvm-version 6.0
1314

1415
#![crate_type = "lib"]
1516
#![feature(custom_attribute)]
@@ -52,16 +53,14 @@ pub fn named_borrow<'r>(_: &'r i32) {
5253
pub fn unsafe_borrow(_: &UnsafeInner) {
5354
}
5455

55-
// CHECK: @mutable_unsafe_borrow(i16* dereferenceable(2) %arg0)
56+
// CHECK: @mutable_unsafe_borrow(i16* noalias dereferenceable(2) %arg0)
5657
// ... unless this is a mutable borrow, those never alias
57-
// ... except that there's this LLVM bug that forces us to not use noalias, see #29485
5858
#[no_mangle]
5959
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
6060
}
6161

62-
// CHECK: @mutable_borrow(i32* dereferenceable(4) %arg0)
62+
// CHECK: @mutable_borrow(i32* noalias dereferenceable(4) %arg0)
6363
// FIXME #25759 This should also have `nocapture`
64-
// ... there's this LLVM bug that forces us to not use noalias, see #29485
6564
#[no_mangle]
6665
pub fn mutable_borrow(_: &mut i32) {
6766
}
@@ -103,9 +102,8 @@ pub fn helper(_: usize) {
103102
pub fn slice(_: &[u8]) {
104103
}
105104

106-
// CHECK: @mutable_slice([0 x i8]* nonnull %arg0.0, [[USIZE]] %arg0.1)
105+
// CHECK: @mutable_slice([0 x i8]* noalias nonnull %arg0.0, [[USIZE]] %arg0.1)
107106
// FIXME #25759 This should also have `nocapture`
108-
// ... there's this LLVM bug that forces us to not use noalias, see #29485
109107
#[no_mangle]
110108
pub fn mutable_slice(_: &mut [u8]) {
111109
}

0 commit comments

Comments
 (0)