about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-11-10 10:26:33 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-11-21 20:05:16 +0100
commit2f00e86cb5cbb4d4cfe17abc6136aacadbe02382 (patch)
treebe9892b5dbd8e1f80ecd4a335483a0cd1b7d8a93 /src/test/codegen
parent35ef33a89dfd8ff8c8a7b3c58fa7136bbcb2f1ed (diff)
downloadrust-2f00e86cb5cbb4d4cfe17abc6136aacadbe02382.tar.gz
rust-2f00e86cb5cbb4d4cfe17abc6136aacadbe02382.zip
Introduce MIR optimizations for simplifying `x?` on `Result`s.
This optimization depends on inlining for the identity
conversions introduced by the lowering of the `?`.
To take advantage of `SimplifyArmIdentity`, `-Z mir-opt-level=2`
is required because that triggers the inlining MIR optimization.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/match.rs8
-rw-r--r--src/test/codegen/try_identity.rs17
2 files changed, 22 insertions, 3 deletions
diff --git a/src/test/codegen/match.rs b/src/test/codegen/match.rs
index 145d4ba6b4c..b5ee5ba2394 100644
--- a/src/test/codegen/match.rs
+++ b/src/test/codegen/match.rs
@@ -9,19 +9,21 @@ pub enum E {
 
 // CHECK-LABEL: @exhaustive_match
 #[no_mangle]
-pub fn exhaustive_match(e: E, unit: ()) {
+pub fn exhaustive_match(e: E) -> u8 {
 // CHECK: switch{{.*}}, label %[[OTHERWISE:[a-zA-Z0-9_]+]] [
 // CHECK-NEXT: i[[TY:[0-9]+]] [[DISCR:[0-9]+]], label %[[A:[a-zA-Z0-9_]+]]
 // CHECK-NEXT: i[[TY:[0-9]+]] [[DISCR:[0-9]+]], label %[[B:[a-zA-Z0-9_]+]]
 // CHECK-NEXT: ]
 // CHECK: [[B]]:
+// CHECK-NEXT: store i8 1, i8* %1, align 1
 // CHECK-NEXT: br label %[[EXIT:[a-zA-Z0-9_]+]]
 // CHECK: [[OTHERWISE]]:
 // CHECK-NEXT: unreachable
 // CHECK: [[A]]:
+// CHECK-NEXT: store i8 0, i8* %1, align 1
 // CHECK-NEXT: br label %[[EXIT:[a-zA-Z0-9_]+]]
     match e {
-        E::A => unit,
-        E::B => unit,
+        E::A => 0,
+        E::B => 1,
     }
 }
diff --git a/src/test/codegen/try_identity.rs b/src/test/codegen/try_identity.rs
new file mode 100644
index 00000000000..30e7adfddf7
--- /dev/null
+++ b/src/test/codegen/try_identity.rs
@@ -0,0 +1,17 @@
+// compile-flags: -C no-prepopulate-passes -Z mir-opt-level=2
+
+// Ensure that `x?` has no overhead on `Result<T, E>` due to identity `match`es in lowering.
+// This requires inlining to trigger the MIR optimizations in `SimplifyArmIdentity`.
+
+#![crate_type = "lib"]
+
+type R = Result<u64, i32>;
+
+#[no_mangle]
+fn try_identity(x: R) -> R {
+// CHECK: start:
+// CHECK-NOT: br {{.*}}
+// CHECK ret void
+    let y = x?;
+    Ok(y)
+}