We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 2b67288 + cf92b22 commit 2408dfeCopy full SHA for 2408dfe
1 file changed
tests/codegen-llvm/issues/signed-nonzero-matches.rs
@@ -0,0 +1,24 @@
1
+// Matching a signed non-zero value against -1 or 1 should not require
2
+// branching code.
3
+
4
+//@ compile-flags: -Copt-level=3
5
6
+#![crate_type = "lib"]
7
8
+use std::num::NonZeroI32;
9
10
+// CHECK-LABEL: @signed_nonzero_matches
11
+#[no_mangle]
12
+pub fn signed_nonzero_matches(n: NonZeroI32) -> bool {
13
+ // CHECK-NOT: br i1
14
+ // CHECK: ret i1
15
+ matches!(n.get(), -1 | 1)
16
+}
17
18
+// CHECK-LABEL: @signed_nonzero_eq
19
20
+pub fn signed_nonzero_eq(n: NonZeroI32) -> bool {
21
22
23
+ n.get() == -1 || n.get() == 1
24
0 commit comments