about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-10-10 18:42:40 +0000
committerbors <bors@rust-lang.org>2022-10-10 18:42:40 +0000
commita6b7274a462829f8ef08a1ddcdcec7ac80dbf3e1 (patch)
treeaa8d4d69987868dd1f3b7e8a1dd353f87c6c223b /src/test/codegen
parent0265a3e93bf1b89d97cae113ed214954d5c35e22 (diff)
parent31cd0aa823a379b6c0d0f66ba4172585d1780e8b (diff)
downloadrust-a6b7274a462829f8ef08a1ddcdcec7ac80dbf3e1.tar.gz
rust-a6b7274a462829f8ef08a1ddcdcec7ac80dbf3e1.zip
Auto merge of #102596 - scottmcm:option-bool-calloc, r=Mark-Simulacrum
Do the `calloc` optimization for `Option<bool>`

Inspired by <https://old.reddit.com/r/rust/comments/xtiqj8/why_is_this_functional_version_faster_than_my_for/iqqy37b/>.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/vec-calloc.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/test/codegen/vec-calloc.rs b/src/test/codegen/vec-calloc.rs
index 435a4ab5187..ae6e448f172 100644
--- a/src/test/codegen/vec-calloc.rs
+++ b/src/test/codegen/vec-calloc.rs
@@ -1,4 +1,4 @@
-// compile-flags: -O
+// compile-flags: -O -Z merge-functions=disabled
 // only-x86_64
 // ignore-debug
 // min-llvm-version: 15.0
@@ -144,6 +144,23 @@ pub fn vec_non_zero_tuple(n: usize) -> Vec<(i16, u8, char)> {
     vec![(0, 0, 'A'); n]
 }
 
+// CHECK-LABEL: @vec_option_bool
+#[no_mangle]
+pub fn vec_option_bool(n: usize) -> Vec<Option<bool>> {
+    // CHECK-NOT: call {{.*}}alloc::vec::from_elem
+    // CHECK-NOT: call {{.*}}reserve
+    // CHECK-NOT: call {{.*}}__rust_alloc(
+
+    // CHECK: call {{.*}}__rust_alloc_zeroed(
+
+    // CHECK-NOT: call {{.*}}alloc::vec::from_elem
+    // CHECK-NOT: call {{.*}}reserve
+    // CHECK-NOT: call {{.*}}__rust_alloc(
+
+    // CHECK: ret void
+    vec![Some(false); n]
+}
+
 // Ensure that __rust_alloc_zeroed gets the right attributes for LLVM to optimize it away.
 // CHECK: declare noalias ptr @__rust_alloc_zeroed(i64, i64 allocalign) unnamed_addr [[RUST_ALLOC_ZEROED_ATTRS:#[0-9]+]]