summaryrefslogtreecommitdiffstats
path: root/tests/codegen/array-equality.rs
blob: abfe295f8b677fa993e8b6bfa05d0e512415caee (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// compile-flags: -O -Z merge-functions=disabled
// 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_char_eq
#[no_mangle]
pub fn array_char_eq(a: [char; 2], b: [char; 2]) -> bool {
    // CHECK-NEXT: start:
    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i64 %0, %1
    // 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_none_short(i40
#[no_mangle]
pub fn array_eq_none_short(x: [Option<std::num::NonZeroU8>; 5]) -> bool {
    // CHECK-NEXT: start:
    // CHECK-NEXT: %[[EQ:.+]] = icmp eq i40 %0, 0
    // CHECK-NEXT: ret i1 %[[EQ]]
    x == [None; 5]
}

// CHECK-LABEL: @array_eq_zero_nested(
#[no_mangle]
pub fn array_eq_zero_nested(x: [[u8; 3]; 3]) -> bool {
    // CHECK: %[[VAL:.+]] = load i72
    // CHECK-SAME: align 1
    // CHECK: %[[EQ:.+]] = icmp eq i72 %[[VAL]], 0
    // CHECK: ret i1 %[[EQ]]
    x == [[0; 3]; 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]
}