about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-02-15 10:44:40 +0100
committerRalf Jung <post@ralfj.de>2023-02-15 10:44:40 +0100
commit1a2908bfaa4e8283b08aa3c29ff41515f247e322 (patch)
treeba0769c8b2e29eb20b5f935fba4567c73e4ec0b9 /tests/codegen
parentf407e96b263e5ce71cde4bf93ad1865119ea45ad (diff)
parent90f642bb3d74ee0ba8e0faf967748f36ff78d572 (diff)
downloadrust-1a2908bfaa4e8283b08aa3c29ff41515f247e322.tar.gz
rust-1a2908bfaa4e8283b08aa3c29ff41515f247e322.zip
Merge from rustc
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/array-map.rs49
-rw-r--r--tests/codegen/autovectorize-f32x4.rs13
-rw-r--r--tests/codegen/consts.rs1
-rw-r--r--tests/codegen/instrument-xray/basic.rs9
-rw-r--r--tests/codegen/instrument-xray/options-combine.rs12
-rw-r--r--tests/codegen/instrument-xray/options-override.rs11
-rw-r--r--tests/codegen/issue-75659.rs2
-rw-r--r--tests/codegen/merge-functions.rs1
-rw-r--r--tests/codegen/sse42-implies-crc32.rs1
-rw-r--r--tests/codegen/uninit-consts.rs1
-rw-r--r--tests/codegen/vec-in-place.rs1
11 files changed, 94 insertions, 7 deletions
diff --git a/tests/codegen/array-map.rs b/tests/codegen/array-map.rs
new file mode 100644
index 00000000000..9298e89e397
--- /dev/null
+++ b/tests/codegen/array-map.rs
@@ -0,0 +1,49 @@
+// compile-flags: -C opt-level=3 -C target-cpu=x86-64-v3
+// no-system-llvm
+// only-x86_64
+// ignore-debug (the extra assertions get in the way)
+
+#![crate_type = "lib"]
+#![feature(array_zip)]
+
+// CHECK-LABEL: @short_integer_map
+#[no_mangle]
+pub fn short_integer_map(x: [u32; 8]) -> [u32; 8] {
+    // CHECK: load <8 x i32>
+    // CHECK: shl <8 x i32>
+    // CHECK: or <8 x i32>
+    // CHECK: store <8 x i32>
+    x.map(|x| 2 * x + 1)
+}
+
+// CHECK-LABEL: @short_integer_zip_map
+#[no_mangle]
+pub fn short_integer_zip_map(x: [u32; 8], y: [u32; 8]) -> [u32; 8] {
+    // CHECK: %[[A:.+]] = load <8 x i32>
+    // CHECK: %[[B:.+]] = load <8 x i32>
+    // CHECK: sub <8 x i32> %[[A]], %[[B]]
+    // CHECK: store <8 x i32>
+    x.zip(y).map(|(x, y)| x - y)
+}
+
+// This test is checking that LLVM can SRoA away a bunch of the overhead,
+// like fully moving the iterators to registers.  Notably, previous implementations
+// of `map` ended up `alloca`ing the whole `array::IntoIterator`, meaning both a
+// hard-to-eliminate `memcpy` and that the iteration counts needed to be written
+// out to stack every iteration, even for infallible operations on `Copy` types.
+//
+// This is still imperfect, as there's more copies than would be ideal,
+// but hopefully work like #103830 will improve that in future,
+// and update this test to be stricter.
+//
+// CHECK-LABEL: @long_integer_map
+#[no_mangle]
+pub fn long_integer_map(x: [u32; 64]) -> [u32; 64] {
+    // CHECK: start:
+    // CHECK-NEXT: alloca [64 x i32]
+    // CHECK-NEXT: alloca %"core::mem::manually_drop::ManuallyDrop<[u32; 64]>"
+    // CHECK-NOT: alloca
+    // CHECK: mul <{{[0-9]+}} x i32>
+    // CHECK: add <{{[0-9]+}} x i32>
+    x.map(|x| 13 * x + 7)
+}
diff --git a/tests/codegen/autovectorize-f32x4.rs b/tests/codegen/autovectorize-f32x4.rs
index 6b09c8fc998..9ecea53f1c0 100644
--- a/tests/codegen/autovectorize-f32x4.rs
+++ b/tests/codegen/autovectorize-f32x4.rs
@@ -1,6 +1,7 @@
-// compile-flags: -C opt-level=3
+// compile-flags: -C opt-level=3 -Z merge-functions=disabled
 // only-x86_64
 #![crate_type = "lib"]
+#![feature(array_zip)]
 
 // CHECK-LABEL: @auto_vectorize_direct
 #[no_mangle]
@@ -30,3 +31,13 @@ pub fn auto_vectorize_loop(a: [f32; 4], b: [f32; 4]) -> [f32; 4] {
     }
     c
 }
+
+// CHECK-LABEL: @auto_vectorize_array_zip_map
+#[no_mangle]
+pub fn auto_vectorize_array_zip_map(a: [f32; 4], b: [f32; 4]) -> [f32; 4] {
+// CHECK: load <4 x float>
+// CHECK: load <4 x float>
+// CHECK: fadd <4 x float>
+// CHECK: store <4 x float>
+    a.zip(b).map(|(a, b)| a + b)
+}
diff --git a/tests/codegen/consts.rs b/tests/codegen/consts.rs
index 260d9de8670..d0418d11142 100644
--- a/tests/codegen/consts.rs
+++ b/tests/codegen/consts.rs
@@ -1,5 +1,4 @@
 // compile-flags: -C no-prepopulate-passes
-// min-llvm-version: 14.0
 
 #![crate_type = "lib"]
 
diff --git a/tests/codegen/instrument-xray/basic.rs b/tests/codegen/instrument-xray/basic.rs
new file mode 100644
index 00000000000..d3e49d53174
--- /dev/null
+++ b/tests/codegen/instrument-xray/basic.rs
@@ -0,0 +1,9 @@
+// Checks that `-Z instrument-xray` produces expected instrumentation.
+//
+// needs-xray
+// compile-flags: -Z instrument-xray=always
+
+#![crate_type = "lib"]
+
+// CHECK: attributes #{{.*}} "function-instrument"="xray-always"
+pub fn function() {}
diff --git a/tests/codegen/instrument-xray/options-combine.rs b/tests/codegen/instrument-xray/options-combine.rs
new file mode 100644
index 00000000000..f7e500b65f6
--- /dev/null
+++ b/tests/codegen/instrument-xray/options-combine.rs
@@ -0,0 +1,12 @@
+// Checks that `-Z instrument-xray` options can be specified multiple times.
+//
+// needs-xray
+// compile-flags: -Z instrument-xray=skip-exit
+// compile-flags: -Z instrument-xray=instruction-threshold=123
+// compile-flags: -Z instrument-xray=instruction-threshold=456
+
+#![crate_type = "lib"]
+
+// CHECK:      attributes #{{.*}} "xray-instruction-threshold"="456" "xray-skip-exit"
+// CHECK-NOT:  attributes #{{.*}} "xray-instruction-threshold"="123"
+pub fn function() {}
diff --git a/tests/codegen/instrument-xray/options-override.rs b/tests/codegen/instrument-xray/options-override.rs
new file mode 100644
index 00000000000..00f81837902
--- /dev/null
+++ b/tests/codegen/instrument-xray/options-override.rs
@@ -0,0 +1,11 @@
+// Checks that the last `-Z instrument-xray` option wins.
+//
+// needs-xray
+// compile-flags: -Z instrument-xray=always
+// compile-flags: -Z instrument-xray=never
+
+#![crate_type = "lib"]
+
+// CHECK:      attributes #{{.*}} "function-instrument"="xray-never"
+// CHECK-NOT:  attributes #{{.*}} "function-instrument"="xray-always"
+pub fn function() {}
diff --git a/tests/codegen/issue-75659.rs b/tests/codegen/issue-75659.rs
index 6bcb59affe3..9394868c08d 100644
--- a/tests/codegen/issue-75659.rs
+++ b/tests/codegen/issue-75659.rs
@@ -1,7 +1,7 @@
 // This test checks that the call to memchr/slice_contains is optimized away
 // when searching in small slices.
 
-// compile-flags: -O -Zinline-mir=no
+// compile-flags: -O -Zinline-mir=false
 // only-x86_64
 
 #![crate_type = "lib"]
diff --git a/tests/codegen/merge-functions.rs b/tests/codegen/merge-functions.rs
index 8e8fe5c964d..d6caeeee896 100644
--- a/tests/codegen/merge-functions.rs
+++ b/tests/codegen/merge-functions.rs
@@ -1,4 +1,3 @@
-// min-llvm-version: 14.0
 // revisions: O Os
 //[Os] compile-flags: -Copt-level=s
 //[O] compile-flags: -O
diff --git a/tests/codegen/sse42-implies-crc32.rs b/tests/codegen/sse42-implies-crc32.rs
index 47b1a899340..56079d32a8d 100644
--- a/tests/codegen/sse42-implies-crc32.rs
+++ b/tests/codegen/sse42-implies-crc32.rs
@@ -1,5 +1,4 @@
 // only-x86_64
-// min-llvm-version: 14.0
 // compile-flags: -Copt-level=3
 
 #![crate_type = "lib"]
diff --git a/tests/codegen/uninit-consts.rs b/tests/codegen/uninit-consts.rs
index 98a6761f8ab..54e9a9e9bb8 100644
--- a/tests/codegen/uninit-consts.rs
+++ b/tests/codegen/uninit-consts.rs
@@ -1,5 +1,4 @@
 // compile-flags: -C no-prepopulate-passes
-// min-llvm-version: 14.0
 
 // Check that we use undef (and not zero) for uninitialized bytes in constants.
 
diff --git a/tests/codegen/vec-in-place.rs b/tests/codegen/vec-in-place.rs
index 5df3669056d..9992604221b 100644
--- a/tests/codegen/vec-in-place.rs
+++ b/tests/codegen/vec-in-place.rs
@@ -1,4 +1,3 @@
-// min-llvm-version: 14.0
 // ignore-debug: the debug assertions get in the way
 // compile-flags: -O -Z merge-functions=disabled
 #![crate_type = "lib"]