about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-08-20 19:32:12 +0200
committerGitHub <noreply@github.com>2022-08-20 19:32:12 +0200
commit45568bdaf7898e29d6a7a721c9a1937fbb2dba55 (patch)
treea15da88b2ab6fb37b5f4f10235b1d92656f45993 /src
parent51769af6ea04a823c94b9374ee0058ae3ac4c4e4 (diff)
parent5145c970871e2dbe37228280fe34decd8c26ea4e (diff)
downloadrust-45568bdaf7898e29d6a7a721c9a1937fbb2dba55.tar.gz
rust-45568bdaf7898e29d6a7a721c9a1937fbb2dba55.zip
Rollup merge of #100693 - scottmcm:new-llvm15-nops, r=Mark-Simulacrum
Add LLVM15-specific codegen test for `try`/`?`s that now optimize away

These still generated a bunch of code back in Rust 1.63 (<https://rust.godbolt.org/z/z31P8h6rz>), but with LLVM 15 merged they no longer do 🎉
Diffstat (limited to 'src')
-rw-r--r--src/test/codegen/try_question_mark_nop.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test/codegen/try_question_mark_nop.rs b/src/test/codegen/try_question_mark_nop.rs
new file mode 100644
index 00000000000..d239387768e
--- /dev/null
+++ b/src/test/codegen/try_question_mark_nop.rs
@@ -0,0 +1,54 @@
+// min-llvm-version: 15.0
+// compile-flags: -O -Z merge-functions=disabled --edition=2021
+// only-x86_64
+
+#![crate_type = "lib"]
+#![feature(try_blocks)]
+
+// These are now NOPs in LLVM 15, presumably thanks to nikic's change mentioned in
+// <https://github.com/rust-lang/rust/issues/85133#issuecomment-1072168354>.
+// Unfortunately, as of 2022-08-17 they're not yet nops for `u64`s nor `Option`.
+
+use std::ops::ControlFlow::{self, Continue, Break};
+
+// CHECK-LABEL: @result_nop_match_32
+#[no_mangle]
+pub fn result_nop_match_32(x: Result<i32, u32>) -> Result<i32, u32> {
+    // CHECK: start
+    // CHECK-NEXT: ret i64 %0
+    match x {
+        Ok(x) => Ok(x),
+        Err(x) => Err(x),
+    }
+}
+
+// CHECK-LABEL: @result_nop_traits_32
+#[no_mangle]
+pub fn result_nop_traits_32(x: Result<i32, u32>) -> Result<i32, u32> {
+    // CHECK: start
+    // CHECK-NEXT: ret i64 %0
+    try {
+        x?
+    }
+}
+
+// CHECK-LABEL: @control_flow_nop_match_32
+#[no_mangle]
+pub fn control_flow_nop_match_32(x: ControlFlow<i32, u32>) -> ControlFlow<i32, u32> {
+    // CHECK: start
+    // CHECK-NEXT: ret i64 %0
+    match x {
+        Continue(x) => Continue(x),
+        Break(x) => Break(x),
+    }
+}
+
+// CHECK-LABEL: @control_flow_nop_traits_32
+#[no_mangle]
+pub fn control_flow_nop_traits_32(x: ControlFlow<i32, u32>) -> ControlFlow<i32, u32> {
+    // CHECK: start
+    // CHECK-NEXT: ret i64 %0
+    try {
+        x?
+    }
+}