about summary refs log tree commit diff
path: root/tests/codegen/enum
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-09 01:02:29 +0000
committerbors <bors@rust-lang.org>2024-04-09 01:02:29 +0000
commit59c808fcd9eeb3c5528209d1cef3aaa5521edbd6 (patch)
tree60071224aa83a816016b41d2cbaa37917baeb03f /tests/codegen/enum
parentb234e449443a49ab19ef6b712bf56cc65927d98f (diff)
parent166bb1bd463dbf6cd3bade6a6b1434884666f032 (diff)
downloadrust-59c808fcd9eeb3c5528209d1cef3aaa5521edbd6.tar.gz
rust-59c808fcd9eeb3c5528209d1cef3aaa5521edbd6.zip
Auto merge of #122387 - DianQK:re-enable-early-otherwise-branch, r=cjgillot
Re-enable the early otherwise branch optimization

Closes #95162. Fixes #119014.

This is the first part of #121397.

An invalid enum discriminant can come from anywhere. We have to check to see if all successors contain the discriminant statement. This should have a pass to hoist instructions.

r? cjgillot
Diffstat (limited to 'tests/codegen/enum')
-rw-r--r--tests/codegen/enum/enum-early-otherwise-branch.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/codegen/enum/enum-early-otherwise-branch.rs b/tests/codegen/enum/enum-early-otherwise-branch.rs
new file mode 100644
index 00000000000..6c7548912da
--- /dev/null
+++ b/tests/codegen/enum/enum-early-otherwise-branch.rs
@@ -0,0 +1,26 @@
+//@ compile-flags: -O
+//@ min-llvm-version: 18
+
+#![crate_type = "lib"]
+
+pub enum Enum {
+    A(u32),
+    B(u32),
+    C(u32),
+}
+
+#[no_mangle]
+pub fn foo(lhs: &Enum, rhs: &Enum) -> bool {
+    // CHECK-LABEL: define{{.*}}i1 @foo(
+    // CHECK-NOT: switch
+    // CHECK-NOT: br
+    // CHECK: [[SELECT:%.*]] = select
+    // CHECK-NEXT: ret i1 [[SELECT]]
+    // CHECK-NEXT: }
+    match (lhs, rhs) {
+        (Enum::A(lhs), Enum::A(rhs)) => lhs == rhs,
+        (Enum::B(lhs), Enum::B(rhs)) => lhs == rhs,
+        (Enum::C(lhs), Enum::C(rhs)) => lhs == rhs,
+        _ => false,
+    }
+}