Add LLVM 18 compat patches

This commit is contained in:
Nikita Popov 2024-03-06 17:56:41 +01:00
parent 504e9e1d44
commit 15b7bb28e4
3 changed files with 124 additions and 0 deletions

62
120529.patch Normal file
View File

@ -0,0 +1,62 @@
From 8eb48b4f4c6e3d48f2600159a75184ec4d74b249 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov@redhat.com>
Date: Wed, 31 Jan 2024 15:08:08 +0100
Subject: [PATCH] Update data layouts in custom target tests for LLVM 18
Fixes https://github.com/rust-lang/rust/issues/120492.
---
tests/run-make/rust-lld-custom-target/custom-target.json | 2 +-
tests/run-make/rustdoc-target-spec-json-path/target.json | 2 +-
tests/run-make/target-specs/my-awesome-platform.json | 2 +-
.../target-specs/my-x86_64-unknown-linux-gnu-platform.json | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/run-make/rust-lld-custom-target/custom-target.json b/tests/run-make/rust-lld-custom-target/custom-target.json
index 7828a99f235c1..e2c64cbdb43c2 100644
--- a/tests/run-make/rust-lld-custom-target/custom-target.json
+++ b/tests/run-make/rust-lld-custom-target/custom-target.json
@@ -2,7 +2,7 @@
"arch": "x86_64",
"cpu": "x86-64",
"crt-static-respected": true,
- "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
+ "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"dynamic-linking": true,
"env": "gnu",
"has-rpath": true,
diff --git a/tests/run-make/rustdoc-target-spec-json-path/target.json b/tests/run-make/rustdoc-target-spec-json-path/target.json
index 34357182c205e..c478f1196fae0 100644
--- a/tests/run-make/rustdoc-target-spec-json-path/target.json
+++ b/tests/run-make/rustdoc-target-spec-json-path/target.json
@@ -2,7 +2,7 @@
"arch": "x86_64",
"cpu": "x86-64",
"crt-static-respected": true,
- "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
+ "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"dynamic-linking": true,
"env": "gnu",
"executables": true,
diff --git a/tests/run-make/target-specs/my-awesome-platform.json b/tests/run-make/target-specs/my-awesome-platform.json
index 00de3de05f07a..1673ef7bd54d1 100644
--- a/tests/run-make/target-specs/my-awesome-platform.json
+++ b/tests/run-make/target-specs/my-awesome-platform.json
@@ -1,5 +1,5 @@
{
- "data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128",
+ "data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128",
"linker-flavor": "gcc",
"llvm-target": "i686-unknown-linux-gnu",
"target-endian": "little",
diff --git a/tests/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json b/tests/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json
index 6d5e964ed4fee..0cafce15a9fef 100644
--- a/tests/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json
+++ b/tests/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json
@@ -1,6 +1,6 @@
{
"pre-link-args": {"gcc": ["-m64"]},
- "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
+ "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"linker-flavor": "gcc",
"llvm-target": "x86_64-unknown-linux-gnu",
"target-endian": "little",

55
121088.patch Normal file
View File

@ -0,0 +1,55 @@
From 369fff6c0640fe89be9b915adaa83e66a022e00d Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov@redhat.com>
Date: Wed, 14 Feb 2024 16:26:20 +0100
Subject: [PATCH] Implicitly enable evex512 if avx512 is enabled
LLVM 18 requires the evex512 feature to allow use of zmm registers.
LLVM automatically sets it when using a generic CPU, but not when
`-C target-cpu` is specified. This will result either in backend
legalization crashes, or code unexpectedly using ymm instead of
zmm registers.
For now, make sure that `avx512*` features imply `evex512`. Long
term we'll probably have to deal with the AVX10 mess somehow.
---
compiler/rustc_codegen_llvm/src/llvm_util.rs | 4 ++++
tests/ui/asm/x86_64/evex512-implicit-feature.rs | 15 +++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 tests/ui/asm/x86_64/evex512-implicit-feature.rs
diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs
index e48479c8da279..54e8ed85e3250 100644
--- a/compiler/rustc_codegen_llvm/src/llvm_util.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs
@@ -266,6 +266,10 @@ pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> LLVMFeature<'a> {
("riscv32" | "riscv64", "fast-unaligned-access") if get_version().0 <= 17 => {
LLVMFeature::new("unaligned-scalar-mem")
}
+ // For LLVM 18, enable the evex512 target feature if a avx512 target feature is enabled.
+ ("x86", s) if get_version().0 >= 18 && s.starts_with("avx512") => {
+ LLVMFeature::with_dependency(s, TargetFeatureFoldStrength::EnableOnly("evex512"))
+ }
(_, s) => LLVMFeature::new(s),
}
}
diff --git a/tests/ui/asm/x86_64/evex512-implicit-feature.rs b/tests/ui/asm/x86_64/evex512-implicit-feature.rs
new file mode 100644
index 0000000000000..a15060857eccb
--- /dev/null
+++ b/tests/ui/asm/x86_64/evex512-implicit-feature.rs
@@ -0,0 +1,15 @@
+// build-pass
+// only-x86_64
+// compile-flags: --crate-type=lib -C target-cpu=skylake
+
+#![feature(avx512_target_feature)]
+#![feature(stdarch_x86_avx512)]
+
+use std::arch::x86_64::*;
+
+#[target_feature(enable = "avx512f")]
+#[no_mangle]
+pub unsafe fn test(res: *mut f64, p: *const f64) {
+ let arg = _mm512_load_pd(p);
+ _mm512_store_pd(res, _mm512_fmaddsub_pd(arg, arg, arg));
+}

View File

@ -137,6 +137,10 @@ Patch5: 0002-set-an-external-library-path-for-wasm32-wasi.patch
# We don't want to use the bundled library in libsqlite3-sys
Patch6: rustc-1.77.0-unbundle-sqlite.patch
# Backports of fixes for LLVM 18 compatibility
Patch7: 120529.patch
Patch8: 121088.patch
### RHEL-specific patches below ###
# Simple rpm macros for rust-toolset (as opposed to full rust-packaging)
@ -591,6 +595,9 @@ rm -rf %{wasi_libc_dir}/dlmalloc/
%endif
%patch -P6 -p1
%patch -P7 -p1
%patch -P8 -p1
%if %with disabled_libssh2
%patch -P100 -p1
%endif