summaryrefslogtreecommitdiffstats
path: root/src/test/codegen/array-equality.rs
blob: cd5e82a9205c1052420006085fb00f4fa35a43fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// compile-flags: -O
// only-x86_64

#![crate_type = "lib"]

// CHECK-LABEL: @array_eq_value
#[no_mangle]
pub fn array_eq_value(a: [u16; 3], b: [u16; 3]) -> bool {
    // CHECK-NEXT: start:
    // CHECK-NEXT: %2 = icmp eq i48 %0, %1
    // CHECK-NEXT: ret i1 %2
    a == b
}

// CHECK-LABEL: @array_eq_ref
#[no_mangle]
pub fn array_eq_ref(a: &[u16; 3], b: &[u16; 3]) -> bool {
    // CHECK: start:
    // CHECK: load i48, {{i48\*|ptr}} %{{.+}}, align 2
    // CHECK: load i48, {{i48\*|ptr}} %{{.+}}, align 2
    // CHECK: icmp eq i48
    // CHECK-NEXT: ret
    a == b
}

// CHECK-LABEL: @array_eq_value_still_passed_by_pointer
#[no_mangle]
pub fn array_eq_value_still_passed_by_pointer(a: [u16; 9], b: [u16; 9]) -> bool {
    // CHECK-NEXT: start:
    // CHECK: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}({{i8\*|ptr}} {{.*}} dereferenceable(18) %{{.+}}, {{i8\*|ptr}} {{.*}} dereferenceable(18) %{{.+}}, i64 18)
    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
    // CHECK-NEXT: ret i1 %[[EQ]]
    a == b
}

// CHECK-LABEL: @array_eq_long
#[no_mangle]
pub fn array_eq_long(a: &[u16; 1234], b: &[u16; 1234]) -> bool {
    // CHECK-NEXT: start:
    // CHECK: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}({{i8\*|ptr}} {{.*}} dereferenceable(2468) %{{.+}}, {{i8\*|ptr}} {{.*}} dereferenceable(2468) %{{.+}}, i64 2468)
    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
    // CHECK-NEXT: ret i1 %[[EQ]]
    a == b
}

// CHECK-LABEL: @array_eq_zero_short(i48
#[no_mangle]
pub fn array_eq_zero_short(x: [u16; 3]) -> bool {
    // CHECK-NEXT: start:
    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i48 %0, 0
    // CHECK-NEXT: ret i1 %[[EQ]]
    x == [0; 3]
}

// CHECK-LABEL: @array_eq_zero_mid(
#[no_mangle]
pub fn array_eq_zero_mid(x: [u16; 8]) -> bool {
    // CHECK-NEXT: start:
    // CHECK: %[[LOAD:.+]] = load i128,
    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i128 %[[LOAD]], 0
    // CHECK-NEXT: ret i1 %[[EQ]]
    x == [0; 8]
}

// CHECK-LABEL: @array_eq_zero_long(
#[no_mangle]
pub fn array_eq_zero_long(x: [u16; 1234]) -> bool {
    // CHECK-NEXT: start:
    // CHECK-NOT: alloca
    // CHECK: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(
    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
    // CHECK-NEXT: ret i1 %[[EQ]]
    x == [0; 1234]
}