about summary refs log tree commit diff
path: root/tests/assembly-llvm/closure-inherit-target-feature.rs
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-07-21 14:22:51 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-07-22 14:27:48 +0200
commited93c1783b404d728d4809973a0550eb33cd293f (patch)
tree2b62aab8b2482fcde1f9128ff53be8cd66bde847 /tests/assembly-llvm/closure-inherit-target-feature.rs
parentc0b282f0ccdab7523cdb8dfa41b23bed5573da76 (diff)
downloadrust-ed93c1783b404d728d4809973a0550eb33cd293f.tar.gz
rust-ed93c1783b404d728d4809973a0550eb33cd293f.zip
Rename `tests/assembly` into `tests/assembly-llvm`
Diffstat (limited to 'tests/assembly-llvm/closure-inherit-target-feature.rs')
-rw-r--r--tests/assembly-llvm/closure-inherit-target-feature.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/assembly-llvm/closure-inherit-target-feature.rs b/tests/assembly-llvm/closure-inherit-target-feature.rs
new file mode 100644
index 00000000000..069204bbd34
--- /dev/null
+++ b/tests/assembly-llvm/closure-inherit-target-feature.rs
@@ -0,0 +1,59 @@
+//@ only-x86_64
+//@ ignore-sgx Tests incompatible with LVI mitigations
+//@ assembly-output: emit-asm
+// make sure the feature is not enabled at compile-time
+//@ compile-flags: -C opt-level=3 -C target-feature=-sse4.1 -C llvm-args=-x86-asm-syntax=intel
+
+#![crate_type = "rlib"]
+
+use std::arch::x86_64::{__m128, _mm_blend_ps};
+
+// Use an explicit return pointer to prevent tail call optimization.
+#[no_mangle]
+pub unsafe fn sse41_blend_nofeature(x: __m128, y: __m128, ret: *mut __m128) {
+    let f = {
+        // check that _mm_blend_ps is not being inlined into the closure
+        // CHECK-LABEL: {{sse41_blend_nofeature.*closure.*:}}
+        // CHECK-NOT: blendps
+        // CHECK: {{call .*_mm_blend_ps.*}}
+        // CHECK-NOT: blendps
+        // CHECK: ret
+        #[inline(never)]
+        |x, y, ret: *mut __m128| unsafe { *ret = _mm_blend_ps(x, y, 0b0101) }
+    };
+    f(x, y, ret);
+}
+
+#[no_mangle]
+#[target_feature(enable = "sse4.1")]
+pub fn sse41_blend_noinline(x: __m128, y: __m128) -> __m128 {
+    let f = {
+        // check that _mm_blend_ps is being inlined into the closure
+        // CHECK-LABEL: {{sse41_blend_noinline.*closure.*:}}
+        // CHECK-NOT: _mm_blend_ps
+        // CHECK: blendps
+        // CHECK-NOT: _mm_blend_ps
+        // CHECK: ret
+        #[inline(never)]
+        |x, y| unsafe { _mm_blend_ps(x, y, 0b0101) }
+    };
+    f(x, y)
+}
+
+#[no_mangle]
+#[target_feature(enable = "sse4.1")]
+pub fn sse41_blend_doinline(x: __m128, y: __m128) -> __m128 {
+    // check that the closure and _mm_blend_ps are being inlined into the function
+    // CHECK-LABEL: sse41_blend_doinline:
+    // CHECK-NOT: {{sse41_blend_doinline.*closure.*}}
+    // CHECK-NOT: _mm_blend_ps
+    // CHECK: blendps
+    // CHECK-NOT: {{sse41_blend_doinline.*closure.*}}
+    // CHECK-NOT: _mm_blend_ps
+    // CHECK: ret
+    let f = {
+        #[inline]
+        |x, y| unsafe { _mm_blend_ps(x, y, 0b0101) }
+    };
+    f(x, y)
+}