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
|
//@ min-llvm-version: 21
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
//! Tests that matching + eq on `Option<FieldlessEnum>` produces a simple compare with no branching
#![crate_type = "lib"]
#[derive(PartialEq)]
pub enum TwoNum {
A,
B,
}
#[derive(PartialEq)]
pub enum ThreeNum {
A,
B,
C,
}
// CHECK-LABEL: @match_two
#[no_mangle]
pub fn match_two(a: Option<TwoNum>, b: Option<TwoNum>) -> bool {
// CHECK-NEXT: start:
// CHECK-NEXT: icmp eq i8
// CHECK-NEXT: ret
match (a, b) {
(Some(x), Some(y)) => x == y,
(Some(_), None) => false,
(None, Some(_)) => false,
(None, None) => true,
}
}
// CHECK-LABEL: @match_three
#[no_mangle]
pub fn match_three(a: Option<ThreeNum>, b: Option<ThreeNum>) -> bool {
// CHECK-NEXT: start:
// CHECK-NEXT: icmp eq
// CHECK-NEXT: ret
match (a, b) {
(Some(x), Some(y)) => x == y,
(Some(_), None) => false,
(None, Some(_)) => false,
(None, None) => true,
}
}
// CHECK-LABEL: @match_two_ref
#[no_mangle]
pub fn match_two_ref(a: &Option<TwoNum>, b: &Option<TwoNum>) -> bool {
// CHECK-NEXT: start:
// CHECK-NEXT: load i8
// CHECK-NEXT: load i8
// CHECK-NEXT: icmp eq i8
// CHECK-NEXT: ret
match (a, b) {
(Some(x), Some(y)) => x == y,
(Some(_), None) => false,
(None, Some(_)) => false,
(None, None) => true,
}
}
// CHECK-LABEL: @match_three_ref
#[no_mangle]
pub fn match_three_ref(a: &Option<ThreeNum>, b: &Option<ThreeNum>) -> bool {
// CHECK-NEXT: start:
// CHECK-NEXT: load i8
// CHECK-NEXT: load i8
// CHECK-NEXT: icmp eq
// CHECK-NEXT: ret
match (a, b) {
(Some(x), Some(y)) => x == y,
(Some(_), None) => false,
(None, Some(_)) => false,
(None, None) => true,
}
}
|