Skip to content

Commit 2be0d0a

Browse files
committed
Auto merge of #28428 - dotdash:same_adjust, r=nikomatsakis
Currently, we're generating adjustments, for example, to get from &[u8] to &[u8], which is unneeded and kicks us out of trans_into() into trans() which means an additional stack slot and copy in the unoptimized code.
2 parents c9fc4ef + 6def06c commit 2be0d0a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Diff for: src/librustc_typeck/check/coercion.rs

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
110110
a,
111111
b);
112112

113+
if a == b {
114+
return Ok(None);
115+
}
116+
113117
// Consider coercing the subtype to a DST
114118
let unsize = self.unpack_actual_value(a, |a| {
115119
self.coerce_unsized(a, b)

Diff for: src/test/codegen/adjustments.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -C no-prepopulate-passes
12+
13+
// Hack to get the correct size for the length part in slices
14+
// CHECK: @helper([[USIZE:i[0-9]+]])
15+
#[no_mangle]
16+
fn helper(_: usize) {
17+
}
18+
19+
// CHECK-LABEL: @no_op_slice_adjustment
20+
#[no_mangle]
21+
pub fn no_op_slice_adjustment(x: &[u8]) -> &[u8] {
22+
// We used to generate an extra alloca and memcpy for the block's trailing expression value, so
23+
// check that we copy directly to the return value slot
24+
// CHECK: [[SRC:%[0-9]+]] = bitcast { i8*, [[USIZE]] }* %x to
25+
// CHECK: [[DST:%[0-9]+]] = bitcast { i8*, [[USIZE]] }* %sret_slot to i8*
26+
// CHECK: call void @llvm.memcpy.{{.*}}(i8* [[DST]], i8* [[SRC]],
27+
{ x }
28+
}

0 commit comments

Comments
 (0)