Skip to content

Commit

Permalink
Rollup merge of #111618 - cjgillot:name-return-place, r=tmiasko
Browse files Browse the repository at this point in the history
Always name the return place.

MIR opts more and more consider `_0` as just another local, so there is no point in keeping the special case in debug-info logic.
  • Loading branch information
Dylan-DPC authored May 18, 2023
2 parents 8cb5fcb + a60e707 commit 7bc736c
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 187 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_ssa/src/mir/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

let local_ref = &self.locals[local];

// FIXME Should the return place be named?
let name = if bx.sess().fewer_names() || local == mir::RETURN_PLACE {
let name = if bx.sess().fewer_names() {
None
} else {
Some(match whole_local_var.or(fallback_var.clone()) {
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/avr/avr-func-addrspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub enum Either<T, U> { A(T), B(U) }
// with the `ptr` field representing both `&i32` and `fn()` depending on the variant.
// This is incorrect, because `fn()` should be `ptr addrspace(1)`, not `ptr`.

// CHECK: define{{.+}}void @should_not_combine_addrspace({{.+\*|ptr}}{{.+}}sret{{.+}}%0, {{.+\*|ptr}}{{.+}}%x)
// CHECK: define{{.+}}void @should_not_combine_addrspace({{.+\*|ptr}}{{.+}}sret{{.+}}%_0, {{.+\*|ptr}}{{.+}}%x)
#[no_mangle]
#[inline(never)]
pub fn should_not_combine_addrspace(x: Either<&i32, fn()>) -> Either<&i32, fn()> {
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ pub fn inline_enum_const() -> E<i8, i16> {
#[no_mangle]
pub fn low_align_const() -> E<i16, [i16; 3]> {
// Check that low_align_const and high_align_const use the same constant
// CHECK: memcpy.{{.+}}({{i8\*|ptr}} align 2 %{{[0-9]+}}, {{i8\*|ptr}} align 2 {{.*}}[[LOW_HIGH]]{{.*}}, i{{(32|64)}} 8, i1 false)
// CHECK: memcpy.{{.+}}({{i8\*|ptr}} align 2 %0, {{i8\*|ptr}} align 2 {{.*}}[[LOW_HIGH]]{{.*}}, i{{(32|64)}} 8, i1 false)
*&E::A(0)
}

// CHECK-LABEL: @high_align_const
#[no_mangle]
pub fn high_align_const() -> E<i16, i32> {
// Check that low_align_const and high_align_const use the same constant
// CHECK: memcpy.{{.+}}({{i8\*|ptr}} align 4 %{{[0-9]+}}, {{i8\*|ptr}} align 4 {{.*}}[[LOW_HIGH]]{{.*}}, i{{(32|64)}} 8, i1 false)
// CHECK: memcpy.{{.+}}({{i8\*|ptr}} align 4 %0, {{i8\*|ptr}} align 4 {{.*}}[[LOW_HIGH]]{{.*}}, i{{(32|64)}} 8, i1 false)
*&E::A(0)
}
2 changes: 1 addition & 1 deletion tests/codegen/enum-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Enum0 {
// CHECK-NEXT: start:
// CHECK-NEXT: %1 = icmp eq i8 %0, 2
// CHECK-NEXT: %2 = and i8 %0, 1
// CHECK-NEXT: %.0 = select i1 %1, i8 13, i8 %2
// CHECK-NEXT: %_0.0 = select i1 %1, i8 13, i8 %2
#[no_mangle]
pub fn match0(e: Enum0) -> u8 {
use Enum0::*;
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/fewer-names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub fn sum(x: u32, y: u32) -> u32 {

// NO-LABEL: define{{.*}}i32 @sum(i32 noundef %x, i32 noundef %y)
// NO-NEXT: start:
// NO-NEXT: %0 = add i32 %y, %x
// NO-NEXT: ret i32 %0
// NO-NEXT: %z = add i32 %y, %x
// NO-NEXT: ret i32 %z
let z = x + y;
z
}
4 changes: 2 additions & 2 deletions tests/codegen/function-arguments-noopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn borrow_call(x: &i32, f: fn(&i32) -> &i32) -> &i32 {
f(x)
}

// CHECK: void @struct_({{%S\*|ptr}} sret(%S){{( %0)?}}, {{%S\*|ptr}} %x)
// CHECK: void @struct_({{%S\*|ptr}} sret(%S){{( %_0)?}}, {{%S\*|ptr}} %x)
#[no_mangle]
pub fn struct_(x: S) -> S {
x
Expand All @@ -51,7 +51,7 @@ pub fn struct_(x: S) -> S {
// CHECK-LABEL: @struct_call
#[no_mangle]
pub fn struct_call(x: S, f: fn(S) -> S) -> S {
// CHECK: call void %f({{%S\*|ptr}} sret(%S){{( %0)?}}, {{%S\*|ptr}} %{{.+}})
// CHECK: call void %f({{%S\*|ptr}} sret(%S){{( %_0)?}}, {{%S\*|ptr}} %{{.+}})
f(x)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/function-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn notunpin_box(x: Box<NotUnpin>) -> Box<NotUnpin> {
x
}

// CHECK: @struct_return({{%S\*|ptr}} noalias nocapture noundef sret(%S) dereferenceable(32){{( %0)?}})
// CHECK: @struct_return({{%S\*|ptr}} noalias nocapture noundef sret(%S) dereferenceable(32){{( %_0)?}})
#[no_mangle]
pub fn struct_return() -> S {
S {
Expand Down
16 changes: 8 additions & 8 deletions tests/codegen/intrinsics/transmute-niched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ pub unsafe fn check_bool_from_ordering(x: std::cmp::Ordering) -> bool {
// CHECK-LABEL: @check_bool_to_ordering(
#[no_mangle]
pub unsafe fn check_bool_to_ordering(x: bool) -> std::cmp::Ordering {
// CHECK: %0 = zext i1 %x to i8
// OPT: %1 = icmp ule i8 %0, 1
// OPT: call void @llvm.assume(i1 %1)
// OPT: %2 = icmp uge i8 %0, -1
// OPT: %3 = icmp ule i8 %0, 1
// OPT: %4 = or i1 %2, %3
// OPT: call void @llvm.assume(i1 %4)
// CHECK: %_0 = zext i1 %x to i8
// OPT: %0 = icmp ule i8 %_0, 1
// OPT: call void @llvm.assume(i1 %0)
// OPT: %1 = icmp uge i8 %_0, -1
// OPT: %2 = icmp ule i8 %_0, 1
// OPT: %3 = or i1 %1, %2
// OPT: call void @llvm.assume(i1 %3)
// DBG-NOT: icmp
// DBG-NOT: assume
// CHECK: ret i8 %0
// CHECK: ret i8 %_0

transmute(x)
}
12 changes: 6 additions & 6 deletions tests/codegen/intrinsics/transmute-x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ use std::mem::transmute;
#[no_mangle]
pub unsafe fn check_sse_float_to_int(x: __m128) -> __m128i {
// CHECK-NOT: alloca
// CHECK: %1 = load <4 x float>, ptr %x, align 16
// CHECK: store <4 x float> %1, ptr %0, align 16
// CHECK: %0 = load <4 x float>, ptr %x, align 16
// CHECK: store <4 x float> %0, ptr %_0, align 16
transmute(x)
}

// CHECK-LABEL: @check_sse_pair_to_avx(
#[no_mangle]
pub unsafe fn check_sse_pair_to_avx(x: (__m128i, __m128i)) -> __m256i {
// CHECK-NOT: alloca
// CHECK: %1 = load <4 x i64>, ptr %x, align 16
// CHECK: store <4 x i64> %1, ptr %0, align 32
// CHECK: %0 = load <4 x i64>, ptr %x, align 16
// CHECK: store <4 x i64> %0, ptr %_0, align 32
transmute(x)
}

// CHECK-LABEL: @check_sse_pair_from_avx(
#[no_mangle]
pub unsafe fn check_sse_pair_from_avx(x: __m256i) -> (__m128i, __m128i) {
// CHECK-NOT: alloca
// CHECK: %1 = load <4 x i64>, ptr %x, align 32
// CHECK: store <4 x i64> %1, ptr %0, align 16
// CHECK: %0 = load <4 x i64>, ptr %x, align 32
// CHECK: store <4 x i64> %0, ptr %_0, align 16
transmute(x)
}
82 changes: 39 additions & 43 deletions tests/codegen/intrinsics/transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#![feature(inline_const)]
#![allow(unreachable_code)]

use std::mem::MaybeUninit;
use std::intrinsics::{transmute, transmute_unchecked};
use std::mem::MaybeUninit;

// Some of these need custom MIR to not get removed by MIR optimizations.
use std::intrinsics::mir::*;
Expand Down Expand Up @@ -61,7 +61,7 @@ pub unsafe fn check_bigger_array(x: [u32; 3]) -> [u32; 7] {
#[custom_mir(dialect = "runtime", phase = "optimized")]
pub unsafe fn check_to_uninhabited(x: u16) -> BigNever {
// CHECK: call void @llvm.trap
mir!{
mir! {
{
RET = CastTransmute(x);
Return()
Expand All @@ -74,7 +74,7 @@ pub unsafe fn check_to_uninhabited(x: u16) -> BigNever {
#[custom_mir(dialect = "runtime", phase = "optimized")]
pub unsafe fn check_from_uninhabited(x: BigNever) -> u16 {
// CHECK: ret i16 poison
mir!{
mir! {
{
RET = CastTransmute(x);
Return()
Expand All @@ -89,9 +89,7 @@ pub unsafe fn check_intermediate_passthrough(x: u32) -> i32 {
// CHECK: %[[TMP:.+]] = add i32 1, %x
// CHECK: %[[RET:.+]] = add i32 %[[TMP]], 1
// CHECK: ret i32 %[[RET]]
unsafe {
transmute::<u32, i32>(1 + x) + 1
}
unsafe { transmute::<u32, i32>(1 + x) + 1 }
}

// CHECK-LABEL: @check_nop_pair(
Expand All @@ -101,9 +99,7 @@ pub unsafe fn check_nop_pair(x: (u8, i8)) -> (i8, u8) {
// CHECK: %0 = insertvalue { i8, i8 } poison, i8 %x.0, 0
// CHECK: %1 = insertvalue { i8, i8 } %0, i8 %x.1, 1
// CHECK: ret { i8, i8 } %1
unsafe {
transmute(x)
}
unsafe { transmute(x) }
}

// CHECK-LABEL: @check_to_newtype(
Expand Down Expand Up @@ -135,9 +131,9 @@ pub unsafe fn check_aggregate_to_bool(x: Aggregate8) -> bool {
// CHECK-LABEL: @check_aggregate_from_bool(
#[no_mangle]
pub unsafe fn check_aggregate_from_bool(x: bool) -> Aggregate8 {
// CHECK: %0 = alloca %Aggregate8, align 1
// CHECK: %_0 = alloca %Aggregate8, align 1
// CHECK: %[[BYTE:.+]] = zext i1 %x to i8
// CHECK: store i8 %[[BYTE]], ptr %0, align 1
// CHECK: store i8 %[[BYTE]], ptr %_0, align 1
transmute(x)
}

Expand All @@ -162,8 +158,8 @@ pub unsafe fn check_byte_from_bool(x: bool) -> u8 {
// CHECK-LABEL: @check_to_pair(
#[no_mangle]
pub unsafe fn check_to_pair(x: u64) -> Option<i32> {
// CHECK: %0 = alloca { i32, i32 }, align 4
// CHECK: store i64 %x, ptr %0, align 4
// CHECK: %_0 = alloca { i32, i32 }, align 4
// CHECK: store i64 %x, ptr %_0, align 4
transmute(x)
}

Expand All @@ -174,37 +170,37 @@ pub unsafe fn check_from_pair(x: Option<i32>) -> u64 {
// immediates so we can write using the destination alloca's alignment.
const { assert!(std::mem::align_of::<Option<i32>>() == 4) };

// CHECK: %0 = alloca i64, align 8
// CHECK: store i32 %x.0, ptr %1, align 8
// CHECK: store i32 %x.1, ptr %2, align 4
// CHECK: %3 = load i64, ptr %0, align 8
// CHECK: ret i64 %3
// CHECK: %_0 = alloca i64, align 8
// CHECK: store i32 %x.0, ptr %0, align 8
// CHECK: store i32 %x.1, ptr %1, align 4
// CHECK: %2 = load i64, ptr %_0, align 8
// CHECK: ret i64 %2
transmute(x)
}

// CHECK-LABEL: @check_to_float(
#[no_mangle]
pub unsafe fn check_to_float(x: u32) -> f32 {
// CHECK-NOT: alloca
// CHECK: %0 = bitcast i32 %x to float
// CHECK: ret float %0
// CHECK: %_0 = bitcast i32 %x to float
// CHECK: ret float %_0
transmute(x)
}

// CHECK-LABEL: @check_from_float(
#[no_mangle]
pub unsafe fn check_from_float(x: f32) -> u32 {
// CHECK-NOT: alloca
// CHECK: %0 = bitcast float %x to i32
// CHECK: ret i32 %0
// CHECK: %_0 = bitcast float %x to i32
// CHECK: ret i32 %_0
transmute(x)
}

// CHECK-LABEL: @check_to_bytes(
#[no_mangle]
pub unsafe fn check_to_bytes(x: u32) -> [u8; 4] {
// CHECK: %0 = alloca [4 x i8], align 1
// CHECK: store i32 %x, ptr %0, align 1
// CHECK: %_0 = alloca [4 x i8], align 1
// CHECK: store i32 %x, ptr %_0, align 1
transmute(x)
}

Expand All @@ -220,10 +216,10 @@ pub unsafe fn check_from_bytes(x: [u8; 4]) -> u32 {
// CHECK-LABEL: @check_to_aggregate(
#[no_mangle]
pub unsafe fn check_to_aggregate(x: u64) -> Aggregate64 {
// CHECK: %0 = alloca %Aggregate64, align 4
// CHECK: store i64 %x, ptr %0, align 4
// CHECK: %1 = load i64, ptr %0, align 4
// CHECK: ret i64 %1
// CHECK: %_0 = alloca %Aggregate64, align 4
// CHECK: store i64 %x, ptr %_0, align 4
// CHECK: %0 = load i64, ptr %_0, align 4
// CHECK: ret i64 %0
transmute(x)
}

Expand All @@ -240,7 +236,7 @@ pub unsafe fn check_from_aggregate(x: Aggregate64) -> u64 {
#[no_mangle]
pub unsafe fn check_long_array_less_aligned(x: [u64; 100]) -> [u16; 400] {
// CHECK-NEXT: start
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 2 %0, ptr align 8 %x, i64 800, i1 false)
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 2 %_0, ptr align 8 %x, i64 800, i1 false)
// CHECK-NEXT: ret void
transmute(x)
}
Expand All @@ -249,7 +245,7 @@ pub unsafe fn check_long_array_less_aligned(x: [u64; 100]) -> [u16; 400] {
#[no_mangle]
pub unsafe fn check_long_array_more_aligned(x: [u8; 100]) -> [u32; 25] {
// CHECK-NEXT: start
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 1 %x, i64 100, i1 false)
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %_0, ptr align 1 %x, i64 100, i1 false)
// CHECK-NEXT: ret void
transmute(x)
}
Expand All @@ -268,8 +264,8 @@ pub unsafe fn check_pair_with_bool(x: (u8, bool)) -> (bool, i8) {
pub unsafe fn check_float_to_pointer(x: f64) -> *const () {
// CHECK-NOT: alloca
// CHECK: %0 = bitcast double %x to i64
// CHECK: %1 = inttoptr i64 %0 to ptr
// CHECK: ret ptr %1
// CHECK: %_0 = inttoptr i64 %0 to ptr
// CHECK: ret ptr %_0
transmute(x)
}

Expand All @@ -278,8 +274,8 @@ pub unsafe fn check_float_to_pointer(x: f64) -> *const () {
pub unsafe fn check_float_from_pointer(x: *const ()) -> f64 {
// CHECK-NOT: alloca
// CHECK: %0 = ptrtoint ptr %x to i64
// CHECK: %1 = bitcast i64 %0 to double
// CHECK: ret double %1
// CHECK: %_0 = bitcast i64 %0 to double
// CHECK: ret double %_0
transmute(x)
}

Expand Down Expand Up @@ -343,10 +339,10 @@ pub unsafe fn check_issue_110005(x: (usize, bool)) -> Option<Box<[u8]>> {
// CHECK-LABEL: @check_pair_to_dst_ref(
#[no_mangle]
pub unsafe fn check_pair_to_dst_ref<'a>(x: (usize, usize)) -> &'a [u8] {
// CHECK: %0 = inttoptr i64 %x.0 to ptr
// CHECK: %1 = insertvalue { ptr, i64 } poison, ptr %0, 0
// CHECK: %2 = insertvalue { ptr, i64 } %1, i64 %x.1, 1
// CHECK: ret { ptr, i64 } %2
// CHECK: %_0.0 = inttoptr i64 %x.0 to ptr
// CHECK: %0 = insertvalue { ptr, i64 } poison, ptr %_0.0, 0
// CHECK: %1 = insertvalue { ptr, i64 } %0, i64 %x.1, 1
// CHECK: ret { ptr, i64 } %1
transmute(x)
}

Expand All @@ -358,7 +354,7 @@ pub unsafe fn check_issue_109992(x: ()) -> [(); 1] {

// CHECK: start
// CHECK-NEXT: ret void
mir!{
mir! {
{
RET = CastTransmute(x);
Return()
Expand Down Expand Up @@ -390,10 +386,10 @@ pub struct HighAlignScalar(u8);
// CHECK-LABEL: @check_to_overalign(
#[no_mangle]
pub unsafe fn check_to_overalign(x: u64) -> HighAlignScalar {
// CHECK: %0 = alloca %HighAlignScalar, align 8
// CHECK: store i64 %x, ptr %0, align 8
// CHECK: %1 = load i64, ptr %0, align 8
// CHECK: ret i64 %1
// CHECK: %_0 = alloca %HighAlignScalar, align 8
// CHECK: store i64 %x, ptr %_0, align 8
// CHECK: %0 = load i64, ptr %_0, align 8
// CHECK: ret i64 %0
transmute(x)
}

Expand Down
6 changes: 3 additions & 3 deletions tests/codegen/match-optimized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ pub fn exhaustive_match(e: E) -> u8 {
// CHECK-NEXT: unreachable
//
// CHECK: [[A]]:
// CHECK-NEXT: store i8 0, {{i8\*|ptr}} %1, align 1
// CHECK-NEXT: store i8 0, {{i8\*|ptr}} %_0, align 1
// CHECK-NEXT: br label %[[EXIT:[a-zA-Z0-9_]+]]
// CHECK: [[B]]:
// CHECK-NEXT: store i8 1, {{i8\*|ptr}} %1, align 1
// CHECK-NEXT: store i8 1, {{i8\*|ptr}} %_0, align 1
// CHECK-NEXT: br label %[[EXIT]]
// CHECK: [[C]]:
// CHECK-NEXT: store i8 2, {{i8\*|ptr}} %1, align 1
// CHECK-NEXT: store i8 2, {{i8\*|ptr}} %_0, align 1
// CHECK-NEXT: br label %[[EXIT]]
match e {
E::A => 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/mem-replace-big-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn replace_big(dst: &mut Big, src: Big) -> Big {
// For a large type, we expect exactly three `memcpy`s
// CHECK-LABEL: define internal void @{{.+}}mem{{.+}}replace{{.+}}sret(%Big)
// CHECK-NOT: call void @llvm.memcpy
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %0, {{i8\*|ptr}} align 8 %dest, i{{.*}} 56, i1 false)
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %result, {{i8\*|ptr}} align 8 %dest, i{{.*}} 56, i1 false)
// CHECK-NOT: call void @llvm.memcpy
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %dest, {{i8\*|ptr}} align 8 %src, i{{.*}} 56, i1 false)
// CHECK-NOT: call void @llvm.memcpy
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/repeat-trusted-len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use std::iter;
// CHECK-LABEL: @repeat_take_collect
#[no_mangle]
pub fn repeat_take_collect() -> Vec<u8> {
// CHECK: call void @llvm.memset.{{.+}}({{i8\*|ptr}} {{.*}}align 1{{.*}} %{{[0-9]+}}, i8 42, i{{[0-9]+}} 100000, i1 false)
// CHECK: call void @llvm.memset.{{.+}}({{i8\*|ptr}} {{.*}}align 1{{.*}} %0, i8 42, i{{[0-9]+}} 100000, i1 false)
iter::repeat(42).take(100000).collect()
}

// CHECK-LABEL: @repeat_with_take_collect
#[no_mangle]
pub fn repeat_with_take_collect() -> Vec<u8> {
// CHECK: call void @llvm.memset.{{.+}}({{i8\*|ptr}} {{.*}}align 1{{.*}} %{{[0-9]+}}, i8 13, i{{[0-9]+}} 12345, i1 false)
// CHECK: call void @llvm.memset.{{.+}}({{i8\*|ptr}} {{.*}}align 1{{.*}} %0, i8 13, i{{[0-9]+}} 12345, i1 false)
iter::repeat_with(|| 13).take(12345).collect()
}
Loading

0 comments on commit 7bc736c

Please sign in to comment.