From 0f9f241aac21bc77fb9e757da18207abefdc841d Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Mon, 5 Apr 2021 17:17:23 +0000 Subject: [PATCH] [aarch64] add target feature outline-atomics Enable outline-atomics by default as enabled in clang by the following commit https://reviews.llvm.org/rGc5e7e649d537067dec7111f3de1430d0fc8a4d11 Performance improves by several orders of magnitude when using the LSE instructions instead of the ARMv8.0 compatible load/store exclusive instructions. Tested on Graviton2 aarch64-linux with x.py build && x.py install && x.py test --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 5 +++++ src/test/assembly/asm/aarch64-outline-atomics.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/assembly/asm/aarch64-outline-atomics.rs diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index f9172e437733f..2d053abd44efe 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -416,6 +416,11 @@ pub fn llvm_global_features(sess: &Session) -> Vec { // -Ctarget-features features.extend(sess.opts.cg.target_feature.split(',').flat_map(&filter)); + // FIXME: Move outline-atomics to target definition when earliest supported LLVM is 12. + if get_version() >= (12, 0, 0) && sess.target.llvm_target.contains("aarch64-unknown-linux") { + features.push("+outline-atomics".to_string()); + } + features } diff --git a/src/test/assembly/asm/aarch64-outline-atomics.rs b/src/test/assembly/asm/aarch64-outline-atomics.rs new file mode 100644 index 0000000000000..93dda712e1b9b --- /dev/null +++ b/src/test/assembly/asm/aarch64-outline-atomics.rs @@ -0,0 +1,16 @@ +// min-llvm-version: 12.0 +// assembly-output: emit-asm +// compile-flags: -O +// compile-flags: --target aarch64-unknown-linux-gnu +// needs-llvm-components: aarch64 +// only-aarch64 + +#![crate_type = "rlib"] + +use std::sync::atomic::{AtomicI32, Ordering::*}; + +pub fn compare_exchange(a: &AtomicI32) { + // On AArch64 LLVM should outline atomic operations. + // CHECK: __aarch64_cas4_relax + let _ = a.compare_exchange(0, 10, Relaxed, Relaxed); +}