Skip to content

Commit 780d37c

Browse files
committed
Fix and improve codegen tests
1 parent f97aded commit 780d37c

8 files changed

+62
-118
lines changed

src/test/codegen/arg-return-value-in-reg.rs

-32
This file was deleted.

src/test/codegen/array-clone.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
// CHECK-LABEL: @array_clone
66
#[no_mangle]
77
pub fn array_clone(a: &[u8; 2]) -> [u8; 2] {
8-
// CHECK-NOT: getelementptr
9-
// CHECK-NOT: load i8
10-
// CHECK-NOT: zext
11-
// CHECK-NOT: shl
12-
// CHECK: load i16
13-
// CHECK-NEXT: ret i16
8+
// CHECK: getelementptr
9+
// CHECK-NEXT: load i8
10+
// CHECK-NEXT: getelementptr
11+
// CHECK-NEXT: load i8
12+
// CHECK: ret [2 x i8]
13+
a.clone()
14+
}
15+
16+
// CHECK-LABEL: @array_clone_big
17+
#[no_mangle]
18+
pub fn array_clone_big(a: &[u8; 16]) -> [u8; 16] {
19+
// CHECK: getelementptr inbounds [16 x i8]
20+
// CHECK-NEXT: getelementptr inbounds [16 x i8]
21+
// CHECK-NEXT: {{.*}} call {{.*}} @llvm.memcpy.p0i8.p0i8.i64
22+
// CHECK-NEXT: ret void
1423
a.clone()
1524
}

src/test/codegen/array-equality.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,24 @@
33

44
#![crate_type = "lib"]
55

6-
// CHECK-LABEL: @array_eq_value
7-
#[no_mangle]
8-
pub fn array_eq_value(a: [u16; 6], b: [u16; 6]) -> bool {
9-
// CHECK-NEXT: start:
10-
// CHECK-NEXT: %2 = icmp eq i96 %0, %1
11-
// CHECK-NEXT: ret i1 %2
12-
a == b
13-
}
14-
156
// CHECK-LABEL: @array_eq_ref
167
#[no_mangle]
178
pub fn array_eq_ref(a: &[u16; 6], b: &[u16; 6]) -> bool {
18-
// CHECK: start:
19-
// CHECK: load i96, i96* %{{.+}}, align 2
20-
// CHECK: load i96, i96* %{{.+}}, align 2
21-
// CHECK: icmp eq i96
22-
// CHECK-NEXT: ret
9+
// CHECK-NEXT: start:
10+
// CHECK-NEXT: bitcast [6 x i16]
11+
// CHECK-NEXT: bitcast [6 x i16]
12+
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(i8* {{.*}} dereferenceable(12) %{{.+}}, i8* {{.*}} dereferenceable(12) %{{.+}}, i64 12)
13+
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
14+
// CHECK-NEXT: ret i1 %[[EQ]]
2315
a == b
2416
}
2517

2618
// CHECK-LABEL: @array_eq_value_still_passed_by_pointer
2719
#[no_mangle]
2820
pub fn array_eq_value_still_passed_by_pointer(a: [u16; 9], b: [u16; 9]) -> bool {
2921
// CHECK-NEXT: start:
30-
// CHECK-NEXT: bitcast
31-
// CHECK-NEXT: bitcast
22+
// CHECK-NEXT: bitcast [9 x i16]
23+
// CHECK-NEXT: bitcast [9 x i16]
3224
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(i8* {{.*}} dereferenceable(18) %{{.+}}, i8* {{.*}} dereferenceable(18) %{{.+}}, i64 18)
3325
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
3426
// CHECK-NEXT: ret i1 %[[EQ]]
@@ -39,19 +31,21 @@ pub fn array_eq_value_still_passed_by_pointer(a: [u16; 9], b: [u16; 9]) -> bool
3931
#[no_mangle]
4032
pub fn array_eq_long(a: &[u16; 1234], b: &[u16; 1234]) -> bool {
4133
// CHECK-NEXT: start:
42-
// CHECK-NEXT: bitcast
43-
// CHECK-NEXT: bitcast
34+
// CHECK-NEXT: bitcast [1234 x i16]
35+
// CHECK-NEXT: bitcast [1234 x i16]
4436
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(i8* {{.*}} dereferenceable(2468) %{{.+}}, i8* {{.*}} dereferenceable(2468) %{{.+}}, i64 2468)
4537
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
4638
// CHECK-NEXT: ret i1 %[[EQ]]
4739
a == b
4840
}
4941

50-
// CHECK-LABEL: @array_eq_zero(i128 %0)
42+
// CHECK-LABEL: @array_eq_zero
5143
#[no_mangle]
5244
pub fn array_eq_zero(x: [u16; 8]) -> bool {
5345
// CHECK-NEXT: start:
54-
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i128 %0, 0
46+
// CHECK-NEXT: bitcast [8 x i16]
47+
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(i8* {{.*}} dereferenceable(16) %{{.+}}, i8* {{.*}} dereferenceable(16) {{.+}}, i64 16)
48+
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
5549
// CHECK-NEXT: ret i1 %[[EQ]]
5650
x == [0; 8]
5751
}

src/test/codegen/loads.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,30 @@ pub struct Bytes {
1212
// CHECK-LABEL: @borrow
1313
#[no_mangle]
1414
pub fn borrow(x: &i32) -> &i32 {
15-
// CHECK: load {{(i32\*, )?}}i32** %x{{.*}}, !nonnull
15+
// CHECK: load {{(i32\*, )?}}i32** %x{{.*}}, !nonnull
1616
&x; // keep variable in an alloca
1717
x
1818
}
1919

2020
// CHECK-LABEL: @_box
2121
#[no_mangle]
2222
pub fn _box(x: Box<i32>) -> i32 {
23-
// CHECK: load {{(i32\*, )?}}i32** %x{{.*}}, !nonnull
23+
// CHECK: load {{(i32\*, )?}}i32** %x{{.*}}, !nonnull
2424
*x
2525
}
2626

2727
// CHECK-LABEL: small_array_alignment
28-
// The array is loaded as i32, but its alignment is lower, go with 1 byte to avoid target
29-
// dependent alignment
3028
#[no_mangle]
3129
pub fn small_array_alignment(x: [i8; 4]) -> [i8; 4] {
32-
// CHECK: [[VAR:%[0-9]+]] = load {{(i32, )?}}i32* %{{.*}}, align 1
33-
// CHECK: ret i32 [[VAR]]
30+
// CHECK: [[VAR:%[0-9]+]] = load [4 x i8], [4 x i8]* %{{.*}}, align 1
31+
// CHECK: ret [4 x i8] [[VAR]]
3432
x
3533
}
3634

37-
// CHECK-LABEL: small_struct_alignment
38-
// The struct is loaded as i32, but its alignment is lower, go with 1 byte to avoid target
39-
// dependent alignment
35+
// CHECK-LABEL: @small_struct_alignment
4036
#[no_mangle]
4137
pub fn small_struct_alignment(x: Bytes) -> Bytes {
42-
// CHECK: [[VAR:%[0-9]+]] = load {{(i32, )?}}i32* %{{.*}}, align 1
43-
// CHECK: ret i32 [[VAR]]
38+
// TODO-CHECK: [[VAR:%[0-9]+]] = load {{(i32, )?}}i32* %{{.*}}, align 1
39+
// TODO-CHECK: ret i32 [[VAR]]
4440
x
4541
}

src/test/codegen/slice-ref-equality.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
// CHECK-LABEL: @is_zero_slice_short
66
#[no_mangle]
77
pub fn is_zero_slice_short(data: &[u8; 4]) -> bool {
8-
// CHECK: :
9-
// CHECK-NEXT: %[[PTR:.+]] = bitcast [4 x i8]* {{.+}} to i32*
10-
// CHECK-NEXT: %[[LOAD:.+]] = load i32, i32* %[[PTR]], align 1
11-
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0
8+
// CHECK: getelementptr [4 x i8], [4 x i8]*
9+
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}
10+
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
1211
// CHECK-NEXT: ret i1 %[[EQ]]
1312
&data[..] == [0; 4]
1413
}
1514

1615
// CHECK-LABEL: @is_zero_array
1716
#[no_mangle]
1817
pub fn is_zero_array(data: &[u8; 4]) -> bool {
19-
// CHECK: start:
20-
// CHECK-NEXT: %[[PTR:.+]] = bitcast [4 x i8]* {{.+}} to i32*
21-
// CHECK-NEXT: %[[LOAD:.+]] = load i32, i32* %[[PTR]], align 1
22-
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0
18+
// CHECK-NEXT: start:
19+
// CHECK-NEXT: getelementptr [4 x i8], [4 x i8]*
20+
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}
21+
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
2322
// CHECK-NEXT: ret i1 %[[EQ]]
2423
*data == [0; 4]
2524
}

src/test/codegen/stores.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,23 @@ pub struct Bytes {
1111
}
1212

1313
// CHECK-LABEL: small_array_alignment
14-
// The array is stored as i32, but its alignment is lower, go with 1 byte to avoid target
15-
// dependent alignment
1614
#[no_mangle]
1715
pub fn small_array_alignment(x: &mut [i8; 4], y: [i8; 4]) {
18-
// CHECK: [[TMP:%.+]] = alloca i32
19-
// CHECK: %y = alloca [4 x i8]
20-
// CHECK: store i32 %0, i32* [[TMP]]
21-
// CHECK: [[Y8:%[0-9]+]] = bitcast [4 x i8]* %y to i8*
22-
// CHECK: [[TMP8:%[0-9]+]] = bitcast i32* [[TMP]] to i8*
23-
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 [[Y8]], i8* align 4 [[TMP8]], i{{[0-9]+}} 4, i1 false)
16+
// CHECK: [[TMP:%.+]] = alloca [4 x i8], align 1
17+
// CHECK: %y = alloca [4 x i8], align 1
18+
// CHECK: store [4 x i8] %0, [4 x i8]* %y
19+
// CHECK: [[Y8:%[0-9]+]] = bitcast [4 x i8]* %y to i8*
20+
// CHECK: [[TMP8:%[0-9]+]] = bitcast [4 x i8]* [[TMP]] to i8*
2421
*x = y;
2522
}
2623

2724
// CHECK-LABEL: small_struct_alignment
28-
// The struct is stored as i32, but its alignment is lower, go with 1 byte to avoid target
29-
// dependent alignment
3025
#[no_mangle]
3126
pub fn small_struct_alignment(x: &mut Bytes, y: Bytes) {
32-
// CHECK: [[TMP:%.+]] = alloca i32
33-
// CHECK: %y = alloca %Bytes
34-
// CHECK: store i32 %0, i32* [[TMP]]
35-
// CHECK: [[Y8:%[0-9]+]] = bitcast %Bytes* %y to i8*
36-
// CHECK: [[TMP8:%[0-9]+]] = bitcast i32* [[TMP]] to i8*
37-
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 [[Y8]], i8* align 4 [[TMP8]], i{{[0-9]+}} 4, i1 false)
27+
// CHECK: [[TMP:%.+]] = alloca %Bytes, align 1
28+
// CHECK: %y = alloca %Bytes, align 1
29+
// CHECK: store %Bytes %0, %Bytes* %y
30+
// CHECK: [[Y8:%[0-9]+]] = bitcast %Bytes* %y to i8*
31+
// CHECK: [[TMP8:%[0-9]+]] = bitcast %Bytes* [[TMP]] to i8*
3832
*x = y;
3933
}

src/test/codegen/swap-small-types.rs

-18
This file was deleted.

src/test/codegen/union-abi.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#![crate_type="lib"]
88
#![feature(repr_simd)]
99

10+
// CHECK: %UnionF32U32 = type { [1 x i32] }
11+
1012
#[derive(Copy, Clone)]
1113
pub enum Unhab {}
1214

@@ -46,35 +48,35 @@ pub union UnionF32{a:f32}
4648
#[no_mangle]
4749
pub fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }
4850

49-
pub union UnionF32F32{a:f32, b:f32}
51+
pub union UnionF32F32{a: f32, b: f32}
5052

5153
// CHECK: define float @test_UnionF32F32(float %_1)
5254
#[no_mangle]
5355
pub fn test_UnionF32F32(_: UnionF32F32) -> UnionF32F32 { loop {} }
5456

55-
pub union UnionF32U32{a:f32, b:u32}
57+
pub union UnionF32U32{a: f32, b: u32}
5658

57-
// CHECK: define i32 @test_UnionF32U32(i32{{( %0)?}})
59+
// CHECK: define %UnionF32U32 @test_UnionF32U32(%UnionF32U32{{( %0)?}})
5860
#[no_mangle]
5961
pub fn test_UnionF32U32(_: UnionF32U32) -> UnionF32U32 { loop {} }
6062

61-
pub union UnionU128{a:u128}
63+
pub union UnionU128{a: u128}
6264
// CHECK: define i128 @test_UnionU128(i128 %_1)
6365
#[no_mangle]
6466
pub fn test_UnionU128(_: UnionU128) -> UnionU128 { loop {} }
6567

66-
pub union UnionU128x2{a:(u128, u128)}
68+
pub union UnionU128x2{a: (u128, u128)}
6769
// CHECK: define void @test_UnionU128x2(i128 %_1.0, i128 %_1.1)
6870
#[no_mangle]
6971
pub fn test_UnionU128x2(_: UnionU128x2) { loop {} }
7072

7173
#[repr(C)]
72-
pub union CUnionU128x2{a:(u128, u128)}
74+
pub union CUnionU128x2{a: (u128, u128)}
7375
// CHECK: define void @test_CUnionU128x2(%CUnionU128x2* {{.*}} %_1)
7476
#[no_mangle]
7577
pub fn test_CUnionU128x2(_: CUnionU128x2) { loop {} }
7678

77-
pub union UnionBool { b:bool }
79+
pub union UnionBool { b: bool }
7880
// CHECK: define zeroext i1 @test_UnionBool(i8 %b)
7981
#[no_mangle]
8082
pub fn test_UnionBool(b: UnionBool) -> bool { unsafe { b.b } }

0 commit comments

Comments
 (0)