forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#128149 - RalfJung:nontemporal_store, r=jieyouxu,Amanieu,Jubilee nontemporal_store: make sure that the intrinsic is truly just a hint The `!nontemporal` flag for stores in LLVM *sounds* like it is just a hint, but actually, it is not -- at least on x86, non-temporal stores need very special treatment by the programmer or else the Rust memory model breaks down. LLVM still treats these stores as-if they were normal stores for optimizations, which is [highly dubious](llvm/llvm-project#64521). Let's avoid all that dubiousness by making our own non-temporal stores be truly just a hint, which is possible on some targets (e.g. ARM). On all other targets, non-temporal stores become regular stores. ~~Blocked on rust-lang/stdarch#1541 propagating to the rustc repo, to make sure the `_mm_stream` intrinsics are unaffected by this change.~~ Fixes rust-lang#114582 Cc `@Amanieu` `@workingjubilee`
- Loading branch information
Showing
5 changed files
with
62 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
//@ compile-flags: -O | ||
//@revisions: with_nontemporal without_nontemporal | ||
//@[with_nontemporal] compile-flags: --target aarch64-unknown-linux-gnu | ||
//@[with_nontemporal] needs-llvm-components: aarch64 | ||
//@[without_nontemporal] compile-flags: --target x86_64-unknown-linux-gnu | ||
//@[without_nontemporal] needs-llvm-components: x86 | ||
|
||
#![feature(core_intrinsics)] | ||
// Ensure that we *do* emit the `!nontemporal` flag on architectures where it | ||
// is well-behaved, but do *not* emit it on architectures where it is ill-behaved. | ||
// For more context, see <https://github.com/rust-lang/rust/issues/114582> and | ||
// <https://github.com/llvm/llvm-project/issues/64521>. | ||
|
||
#![feature(no_core, lang_items, intrinsics)] | ||
#![no_core] | ||
#![crate_type = "lib"] | ||
|
||
#[lang = "sized"] | ||
pub trait Sized {} | ||
#[lang = "copy"] | ||
pub trait Copy {} | ||
|
||
impl Copy for u32 {} | ||
impl<T> Copy for *mut T {} | ||
|
||
extern "rust-intrinsic" { | ||
pub fn nontemporal_store<T>(ptr: *mut T, val: T); | ||
} | ||
|
||
#[no_mangle] | ||
pub fn a(a: &mut u32, b: u32) { | ||
// CHECK-LABEL: define{{.*}}void @a | ||
// CHECK: store i32 %b, ptr %a, align 4, !nontemporal | ||
// with_nontemporal: store i32 %b, ptr %a, align 4, !nontemporal | ||
// without_nontemporal-NOT: nontemporal | ||
unsafe { | ||
std::intrinsics::nontemporal_store(a, b); | ||
nontemporal_store(a, b); | ||
} | ||
} |