Skip to content

Commit dfc3377

Browse files
committed
Split the mem-replace codegen test
Apparently in CI it's getting generated in the opposite order, one function per file will make the test pass either way.
1 parent e7c6ad8 commit dfc3377

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

tests/codegen/mem-replace-big-type.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This test ensures that `mem::replace::<T>` only ever calls `@llvm.memcpy`
2+
// with `size_of::<T>()` as the size, and never goes through any wrapper that
3+
// may e.g. multiply `size_of::<T>()` with a variable "count" (which is only
4+
// known to be `1` after inlining).
5+
6+
// compile-flags: -C no-prepopulate-passes -Zinline-mir=no
7+
// ignore-debug: the debug assertions get in the way
8+
9+
#![crate_type = "lib"]
10+
11+
#[repr(C, align(8))]
12+
pub struct Big([u64; 7]);
13+
pub fn replace_big(dst: &mut Big, src: Big) -> Big {
14+
// Before the `read_via_copy` intrinsic, this emitted six `memcpy`s.
15+
std::mem::replace(dst, src)
16+
}
17+
18+
// NOTE(eddyb) the `CHECK-NOT`s ensure that the only calls of `@llvm.memcpy` in
19+
// the entire output, are the direct calls we want, from `ptr::replace`.
20+
21+
// CHECK-NOT: call void @llvm.memcpy
22+
23+
// For a large type, we expect exactly three `memcpy`s
24+
// CHECK-LABEL: define internal void @{{.+}}mem{{.+}}replace{{.+}}sret(%Big)
25+
// CHECK-NOT: alloca
26+
// CHECK: alloca %Big
27+
// CHECK-NOT: alloca
28+
// CHECK-NOT: call void @llvm.memcpy
29+
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false)
30+
// CHECK-NOT: call void @llvm.memcpy
31+
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false)
32+
// CHECK-NOT: call void @llvm.memcpy
33+
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false)
34+
// CHECK-NOT: call void @llvm.memcpy
35+
36+
// CHECK-NOT: call void @llvm.memcpy

tests/codegen/mem-replace-direct-memcpy.rs

-22
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,11 @@ pub fn replace_byte(dst: &mut u8, src: u8) -> u8 {
1212
std::mem::replace(dst, src)
1313
}
1414

15-
#[repr(C, align(8))]
16-
pub struct Big([u64; 7]);
17-
pub fn replace_big(dst: &mut Big, src: Big) -> Big {
18-
// Before the `read_via_copy` intrinsic, this emitted six `memcpy`s.
19-
std::mem::replace(dst, src)
20-
}
21-
2215
// NOTE(eddyb) the `CHECK-NOT`s ensure that the only calls of `@llvm.memcpy` in
2316
// the entire output, are the direct calls we want, from `ptr::replace`.
2417

2518
// CHECK-NOT: call void @llvm.memcpy
2619

27-
// For a large type, we expect exactly three `memcpy`s
28-
// CHECK-LABEL: define internal void @{{.+}}mem{{.+}}replace{{.+}}sret(%Big)
29-
// CHECK-NOT: alloca
30-
// CHECK: alloca %Big
31-
// CHECK-NOT: alloca
32-
// CHECK-NOT: call void @llvm.memcpy
33-
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false)
34-
// CHECK-NOT: call void @llvm.memcpy
35-
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false)
36-
// CHECK-NOT: call void @llvm.memcpy
37-
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false)
38-
// CHECK-NOT: call void @llvm.memcpy
39-
40-
// CHECK-NOT: call void @llvm.memcpy
41-
4220
// For a small type, we expect one each of `load`/`store`/`memcpy` instead
4321
// CHECK-LABEL: define internal noundef i8 @{{.+}}mem{{.+}}replace
4422
// CHECK-NOT: alloca

0 commit comments

Comments
 (0)