Skip to content

regression test for intrinsics may not inline properly on pclmulqdq #145001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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