Skip to content

Commit aa299a9

Browse files
committed
Add codegen test for branchy bool match
1 parent f7b5e54 commit aa299a9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ compile-flags: -O -Zmerge-functions=disabled
2+
//! Test for <https://github.com/rust-lang/rust/issues/108395>. Check that
3+
//! matching on two bools with wildcards does not produce branches.
4+
#![crate_type = "lib"]
5+
6+
// CHECK-LABEL: @wildcard(
7+
#[no_mangle]
8+
pub fn wildcard(a: u16, b: u16, v: u16) -> u16 {
9+
// CHECK-NOT: br
10+
match (a == v, b == v) {
11+
(true, false) => 0,
12+
(false, true) => u16::MAX,
13+
_ => 1 << 15, // half
14+
}
15+
}
16+
17+
// CHECK-LABEL: @exhaustive(
18+
#[no_mangle]
19+
pub fn exhaustive(a: u16, b: u16, v: u16) -> u16 {
20+
// CHECK-NOT: br
21+
match (a == v, b == v) {
22+
(true, false) => 0,
23+
(false, true) => u16::MAX,
24+
(true, true) => 1 << 15,
25+
(false, false) => 1 << 15,
26+
}
27+
}

0 commit comments

Comments
 (0)