Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/codegen-llvm/pclmulqdq-target-feature-inlining.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Test for pclmulqdq intrinsics inlining across target_feature boundaries
// Issue: https://github.com/rust-lang/rust/issues/139029
//
// When a function with target_feature calls another function without matching
// target_feature attributes, the intrinsics may not inline properly, leading
// to function calls instead of direct instructions.

//@ only-x86_64
//@ compile-flags: -C opt-level=3

#![crate_type = "lib"]

use std::arch::x86_64 as arch;

// CHECK-LABEL: @reduce128_caller
// CHECK-NOT: call
// CHECK: call <2 x i64> @llvm.x86.pclmulqdq
// CHECK: call <2 x i64> @llvm.x86.pclmulqdq
// CHECK-NOT: call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that this can match the nocallback attribute. I think we can avoid it by adding an extra // CHECK: ret after it.

#[target_feature(enable = "pclmulqdq", enable = "sse2", enable = "sse4.1")]
#[no_mangle]
pub unsafe fn reduce128_caller(
a: arch::__m128i,
b: arch::__m128i,
keys: arch::__m128i,
) -> arch::__m128i {
reduce128(a, b, keys)
}

unsafe fn reduce128(a: arch::__m128i, b: arch::__m128i, keys: arch::__m128i) -> arch::__m128i {
let t1 = arch::_mm_clmulepi64_si128(a, keys, 0x00);
let t2 = arch::_mm_clmulepi64_si128(a, keys, 0x11);
arch::_mm_xor_si128(arch::_mm_xor_si128(b, t1), t2)
}
Loading