Skip to content

Commit 3a694c7

Browse files
authored
Rollup merge of #145355 - clubby789:option-match-eq, r=nikic
Add codegen test for issue 122734 Closes #122734
2 parents 1e454c6 + 9b92069 commit 3a694c7

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//@ min-llvm-version: 21
2+
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
3+
//! Tests that matching + eq on `Option<FieldlessEnum>` produces a simple compare with no branching
4+
5+
#![crate_type = "lib"]
6+
7+
#[derive(PartialEq)]
8+
pub enum TwoNum {
9+
A,
10+
B,
11+
}
12+
13+
#[derive(PartialEq)]
14+
pub enum ThreeNum {
15+
A,
16+
B,
17+
C,
18+
}
19+
20+
// CHECK-LABEL: @match_two
21+
#[no_mangle]
22+
pub fn match_two(a: Option<TwoNum>, b: Option<TwoNum>) -> bool {
23+
// CHECK-NEXT: start:
24+
// CHECK-NEXT: icmp eq i8
25+
// CHECK-NEXT: ret
26+
match (a, b) {
27+
(Some(x), Some(y)) => x == y,
28+
(Some(_), None) => false,
29+
(None, Some(_)) => false,
30+
(None, None) => true,
31+
}
32+
}
33+
34+
// CHECK-LABEL: @match_three
35+
#[no_mangle]
36+
pub fn match_three(a: Option<ThreeNum>, b: Option<ThreeNum>) -> bool {
37+
// CHECK-NEXT: start:
38+
// CHECK-NEXT: icmp eq
39+
// CHECK-NEXT: ret
40+
match (a, b) {
41+
(Some(x), Some(y)) => x == y,
42+
(Some(_), None) => false,
43+
(None, Some(_)) => false,
44+
(None, None) => true,
45+
}
46+
}
47+
48+
// CHECK-LABEL: @match_two_ref
49+
#[no_mangle]
50+
pub fn match_two_ref(a: &Option<TwoNum>, b: &Option<TwoNum>) -> bool {
51+
// CHECK-NEXT: start:
52+
// CHECK-NEXT: load i8
53+
// CHECK-NEXT: load i8
54+
// CHECK-NEXT: icmp eq i8
55+
// CHECK-NEXT: ret
56+
match (a, b) {
57+
(Some(x), Some(y)) => x == y,
58+
(Some(_), None) => false,
59+
(None, Some(_)) => false,
60+
(None, None) => true,
61+
}
62+
}
63+
64+
// CHECK-LABEL: @match_three_ref
65+
#[no_mangle]
66+
pub fn match_three_ref(a: &Option<ThreeNum>, b: &Option<ThreeNum>) -> bool {
67+
// CHECK-NEXT: start:
68+
// CHECK-NEXT: load i8
69+
// CHECK-NEXT: load i8
70+
// CHECK-NEXT: icmp eq
71+
// CHECK-NEXT: ret
72+
match (a, b) {
73+
(Some(x), Some(y)) => x == y,
74+
(Some(_), None) => false,
75+
(None, Some(_)) => false,
76+
(None, None) => true,
77+
}
78+
}

0 commit comments

Comments
 (0)