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
29 changes: 29 additions & 0 deletions tests/codegen-llvm/pclmulqdq-target-feature-inlining.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//@ only-x86_64
//@ compile-flags: -C opt-level=3

//! Regression test for https://github.com/rust-lang/rust/issues/139029
//!
//! pclmulqdq intrinsics should inline across target_feature

@folkertdev folkertdev Jun 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
//! pclmulqdq intrinsics should inline across target_feature
//! The pclmulqdq intrinsics should inline into functions with the required target features.
*[View changes since the review](https://triagebot.infra.rust-lang.org/gh-changes-since/rust-lang/rust/157791/d2f24127d97d8c795d1cf5fbf6037f9885f34d39..e497947ec34512d57dd5fb3a0e24871c7c97337e)*


#![crate_type = "lib"]

use std::arch::x86_64 as arch;

// CHECK-LABEL: @reduce128_caller
// CHECK: call <2 x i64> @llvm.x86.pclmulqdq
// CHECK: call <2 x i64> @llvm.x86.pclmulqdq
Comment on lines +12 to +14

@folkertdev folkertdev Jun 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Currently this only tests that

  • the reduce128_caller function exists
  • call <2 x i64> @llvm.x86.pclmulqdq occurs twice.

But this doesn't test that reduce128 actually got inlined.

View changes since the review

#[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 {

@folkertdev folkertdev Jun 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
unsafe fn reduce128(a: arch::__m128i, b: arch::__m128i, keys: arch::__m128i) -> arch::__m128i {
// CHECK-LABEL: @reduce128
// CHECK: call <2 x i64> @llvm.x86.pclmulqdq
// CHECK: call <2 x i64> @llvm.x86.pclmulqdq
#[no_mangle]
unsafe fn reduce128(a: arch::__m128i, b: arch::__m128i, keys: arch::__m128i) -> arch::__m128i {

With these additional checks the call <2 x i64> @llvm.x86.pclmulqdq must occur 4 times in total, proving that inlining occurred.

View changes since the review

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