Skip to content
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

[LoongArch] Unexpected conditional compilation directive for target_feature #133276

Closed
heiher opened this issue Nov 21, 2024 · 1 comment · Fixed by #133799
Closed

[LoongArch] Unexpected conditional compilation directive for target_feature #133276

heiher opened this issue Nov 21, 2024 · 1 comment · Fixed by #133799
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. C-bug Category: This is a bug. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes O-loongarch Target: LoongArch (LA32R, LA32S, LA64) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@heiher
Copy link
Contributor

heiher commented Nov 21, 2024

I tried this code:

#![feature(stdarch_loongarch)]
use std::arch::loongarch64::*;

#[cfg(target_feature = "lasx")]
pub unsafe fn simd(s: i32) -> i32 {
    lasx_xvpickve2gr_w::<0>(lasx_xvreplgr2vr_w(s))
}
rustc --crate-type lib --emit llvm-ir -o lasx.ll lasx.rs

I expected to see this happen:

The simd function was not compiled due to the missing lasx feature.

Instead, this happened:

The simd function was generated.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (3fee0f12e 2024-11-20)
binary: rustc
commit-hash: 3fee0f12e4f595948f8f54f57c8b7a7a58127124
commit-date: 2024-11-20
host: loongarch64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

rustc -Z unstable-options --print target-spec-json:

{
  "arch": "loongarch64",
  "code-model": "medium",
  "crt-objects-fallback": "false",
  "crt-static-respected": true,
  "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
  "direct-access-external-data": false,
  "dynamic-linking": true,
  "env": "gnu",
  "features": "+f,+d,+lsx",
  "has-rpath": true,
  "has-thread-local": true,
  "linker-flavor": "gnu-cc",
  "llvm-abiname": "lp64d",
  "llvm-target": "loongarch64-unknown-linux-gnu",
  "max-atomic-width": 64,
  "metadata": {
    "description": "LoongArch64 Linux, LP64D ABI (kernel 5.19, glibc 2.36)",
    "host_tools": true,
    "std": true,
    "tier": 2
  },
  "os": "linux",
  "position-independent-executables": true,
  "relro-level": "full",
  "supported-sanitizers": [
    "address",
    "leak",
    "memory",
    "thread",
    "cfi"
  ],
  "supported-split-debuginfo": [
    "packed",
    "unpacked",
    "off"
  ],
  "supports-xray": true,
  "target-family": [
    "unix"
  ],
  "target-pointer-width": "64"
}
@heiher heiher added the C-bug Category: This is a bug. label Nov 21, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 21, 2024
@heiher
Copy link
Contributor Author

heiher commented Nov 21, 2024

Although the lasx feature is not enabled in the LoongArch target specification, the CPU defaults to generic. This is replaced in the LLVM backend with the la464 processor model, which includes the lasx feature.

https://github.com/llvm/llvm-project/tree/llvmorg-19.1.4/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp#L55-L60

static MCSubtargetInfo *
createLoongArchMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
  if (CPU.empty() || CPU == "generic")
    CPU = TT.isArch64Bit() ? "la464" : "generic-la32";
  return createLoongArchMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
}

The issue was addressed in the llvm main branch by llvm/llvm-project#114922. I'll request a backport.

@jieyouxu jieyouxu added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes O-loongarch Target: LoongArch (LA32R, LA32S, LA64) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 21, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 3, 2024
Update LLVM to 19.1.5

Fixes rust-lang#133276. Fixes rust-lang#133203.

r? nikic or wg-llvm
@bors bors closed this as completed in 96e51d9 Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. C-bug Category: This is a bug. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes O-loongarch Target: LoongArch (LA32R, LA32S, LA64) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants