about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-03-22 01:16:29 +0000
committerbors <bors@rust-lang.org>2021-03-22 01:16:29 +0000
commit35385770ae1ea86a911cc44ac43f856831e44b26 (patch)
tree509eb08317fe567c9294f2162699bb310266f52c /src/test/codegen
parent97663b6690689379aa0493deb494dfe14627c46b (diff)
parent2d8be457434103bfeeea59f1882a15760f2a5c70 (diff)
downloadrust-35385770ae1ea86a911cc44ac43f856831e44b26.tar.gz
rust-35385770ae1ea86a911cc44ac43f856831e44b26.zip
Auto merge of #79846 - the8472:inplace-tra, r=m-ou-se
Use TrustedRandomAccess for in-place iterators where possible

This can speed up in-place iterators containing simple casts and transmutes from `Copy` types to any type of same size. `!Copy` types can't be optimized since `TrustedRandomAccess`  isn't implemented for those iterators.

```
 name                  on.b ns/iter     o1.b ns/iter     diff ns/iter   diff %  speedup
 vec::bench_transmute  20 (40000 MB/s)  12 (66666 MB/s)            -8  -40.00%   x 1.67
```
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/vec-in-place.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/codegen/vec-in-place.rs b/src/test/codegen/vec-in-place.rs
new file mode 100644
index 00000000000..72ed7492be9
--- /dev/null
+++ b/src/test/codegen/vec-in-place.rs
@@ -0,0 +1,14 @@
+// ignore-debug: the debug assertions get in the way
+// compile-flags: -O
+// min-llvm-version: 11.0
+#![crate_type = "lib"]
+
+// Ensure that trivial casts of vec elements are O(1)
+
+// CHECK-LABEL: @vec_iterator_cast
+#[no_mangle]
+pub fn vec_iterator_cast(vec: Vec<isize>) -> Vec<usize> {
+    // CHECK-NOT: loop
+    // CHECK-NOT: call
+    vec.into_iter().map(|e| e as usize).collect()
+}