Skip to content

Commit db24d8e

Browse files
committed
Enable emission of alignment attrs for pointer params
Instead disable creation of assumptions during inlining using an LLVM opt flag. The -Z arg-align-attributes option which previously controlled this behavior is removed.
1 parent 0a4a4ff commit db24d8e

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

src/librustc/session/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1271,8 +1271,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12711271
"set the MIR optimization level (0-3, default: 1)"),
12721272
mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
12731273
"emit noalias metadata for mutable references (default: yes on LLVM >= 6)"),
1274-
arg_align_attributes: bool = (false, parse_bool, [TRACKED],
1275-
"emit align metadata for reference arguments"),
12761274
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
12771275
"dump MIR state to file.
12781276
`val` is used to select which passes and functions to dump. For example:

src/librustc_codegen_llvm/abi.rs

-6
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,6 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
489489
attrs.pointee_size = pointee.size;
490490
attrs.pointee_align = Some(pointee.align);
491491

492-
// HACK(eddyb) LLVM inserts `llvm.assume` calls when inlining functions
493-
// with align attributes, and those calls later block optimizations.
494-
if !is_return && !cx.tcx.sess.opts.debugging_opts.arg_align_attributes {
495-
attrs.pointee_align = None;
496-
}
497-
498492
// `Box` pointer parameters never alias because ownership is transferred
499493
// `&mut` pointer parameters never alias other parameters,
500494
// or mutable global data

src/librustc_codegen_llvm/llvm_util.rs

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ unsafe fn configure_llvm(sess: &Session) {
7474
add("-mergefunc-use-aliases");
7575
}
7676

77+
// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
78+
// during inlining. Unfortunately these may block other optimizations.
79+
add("-preserve-alignment-assumptions-during-inlining=false");
80+
7781
for arg in &sess.opts.cg.llvm_args {
7882
add(&(*arg));
7983
}

src/test/codegen/function-arguments.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,37 @@ pub fn boolean(x: bool) -> bool {
2828
x
2929
}
3030

31-
// CHECK: @readonly_borrow(i32* noalias readonly dereferenceable(4) %arg0)
31+
// CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
3232
// FIXME #25759 This should also have `nocapture`
3333
#[no_mangle]
3434
pub fn readonly_borrow(_: &i32) {
3535
}
3636

37-
// CHECK: @static_borrow(i32* noalias readonly dereferenceable(4) %arg0)
37+
// CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
3838
// static borrow may be captured
3939
#[no_mangle]
4040
pub fn static_borrow(_: &'static i32) {
4141
}
4242

43-
// CHECK: @named_borrow(i32* noalias readonly dereferenceable(4) %arg0)
43+
// CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %arg0)
4444
// borrow with named lifetime may be captured
4545
#[no_mangle]
4646
pub fn named_borrow<'r>(_: &'r i32) {
4747
}
4848

49-
// CHECK: @unsafe_borrow(i16* dereferenceable(2) %arg0)
49+
// CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %arg0)
5050
// unsafe interior means this isn't actually readonly and there may be aliases ...
5151
#[no_mangle]
5252
pub fn unsafe_borrow(_: &UnsafeInner) {
5353
}
5454

55-
// CHECK: @mutable_unsafe_borrow(i16* dereferenceable(2) %arg0)
55+
// CHECK: @mutable_unsafe_borrow(i16* align 2 dereferenceable(2) %arg0)
5656
// ... unless this is a mutable borrow, those never alias
5757
#[no_mangle]
5858
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
5959
}
6060

61-
// CHECK: @mutable_borrow(i32* dereferenceable(4) %arg0)
61+
// CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %arg0)
6262
// FIXME #25759 This should also have `nocapture`
6363
#[no_mangle]
6464
pub fn mutable_borrow(_: &mut i32) {
@@ -69,13 +69,13 @@ pub fn mutable_borrow(_: &mut i32) {
6969
pub fn indirect_struct(_: S) {
7070
}
7171

72-
// CHECK: @borrowed_struct(%S* noalias readonly dereferenceable(32) %arg0)
72+
// CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %arg0)
7373
// FIXME #25759 This should also have `nocapture`
7474
#[no_mangle]
7575
pub fn borrowed_struct(_: &S) {
7676
}
7777

78-
// CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4) %x)
78+
// CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias align 4 dereferenceable(4) %x)
7979
#[no_mangle]
8080
pub fn _box(x: Box<i32>) -> Box<i32> {
8181
x
@@ -95,48 +95,48 @@ pub fn struct_return() -> S {
9595
pub fn helper(_: usize) {
9696
}
9797

98-
// CHECK: @slice([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
98+
// CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
9999
// FIXME #25759 This should also have `nocapture`
100100
#[no_mangle]
101101
pub fn slice(_: &[u8]) {
102102
}
103103

104-
// CHECK: @mutable_slice([0 x i8]* nonnull %arg0.0, [[USIZE]] %arg0.1)
104+
// CHECK: @mutable_slice([0 x i8]* nonnull align 1 %arg0.0, [[USIZE]] %arg0.1)
105105
// FIXME #25759 This should also have `nocapture`
106106
#[no_mangle]
107107
pub fn mutable_slice(_: &mut [u8]) {
108108
}
109109

110-
// CHECK: @unsafe_slice([0 x i16]* nonnull %arg0.0, [[USIZE]] %arg0.1)
110+
// CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %arg0.0, [[USIZE]] %arg0.1)
111111
// unsafe interior means this isn't actually readonly and there may be aliases ...
112112
#[no_mangle]
113113
pub fn unsafe_slice(_: &[UnsafeInner]) {
114114
}
115115

116-
// CHECK: @str([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
116+
// CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %arg0.0, [[USIZE]] %arg0.1)
117117
// FIXME #25759 This should also have `nocapture`
118118
#[no_mangle]
119119
pub fn str(_: &[u8]) {
120120
}
121121

122-
// CHECK: @trait_borrow({}* nonnull %arg0.0, [3 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}) %arg0.1)
122+
// CHECK: @trait_borrow({}* nonnull align 1 %arg0.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %arg0.1)
123123
// FIXME #25759 This should also have `nocapture`
124124
#[no_mangle]
125125
pub fn trait_borrow(_: &Drop) {
126126
}
127127

128-
// CHECK: @trait_box({}* noalias nonnull, [3 x [[USIZE]]]* noalias readonly dereferenceable({{.*}}))
128+
// CHECK: @trait_box({}* noalias nonnull align 1, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}))
129129
#[no_mangle]
130130
pub fn trait_box(_: Box<Drop>) {
131131
}
132132

133-
// CHECK: { i8*, i8* } @trait_option(i8* noalias %x.0, i8* %x.1)
133+
// CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1)
134134
#[no_mangle]
135135
pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
136136
x
137137
}
138138

139-
// CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly %x.0, [[USIZE]] %x.1)
139+
// CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
140140
#[no_mangle]
141141
pub fn return_slice(x: &[u16]) -> &[u16] {
142142
x

0 commit comments

Comments
 (0)