Skip to content

[LoongArch] Add processor models la64v1.0 and la64v1.1 #110211

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

Closed
wants to merge 1 commit into from

Conversation

heiher
Copy link
Member

@heiher heiher commented Sep 27, 2024

Add support for the la64v1.0 and la64v1.1 processor models, enabling Rust to select features based on the version of the LoongArch instruction set. These values will align with those used in the C/C++ toolchain. 1

Footnotes

  1. https://github.com/loongson/la-toolchain-conventions?tab=readme-ov-file#list

Add support for the `la64v1.0` and `la64v1.1` processor models, enabling
Rust to select features based on the version of the LoongArch instruction
set. These values will align with those used in the C/C++ toolchain. [^1]

[^1]: https://github.com/loongson/la-toolchain-conventions?tab=readme-ov-file#list
@llvmbot
Copy link
Member

llvmbot commented Sep 27, 2024

@llvm/pr-subscribers-backend-loongarch

Author: hev (heiher)

Changes

Add support for the la64v1.0 and la64v1.1 processor models, enabling Rust to select features based on the version of the LoongArch instruction set. These values will align with those used in the C/C++ toolchain. 1


Full diff: https://github.com/llvm/llvm-project/pull/110211.diff

2 Files Affected:

  • (modified) llvm/lib/Target/LoongArch/LoongArch.td (+28-17)
  • (modified) llvm/test/CodeGen/LoongArch/cpus.ll (+10)
diff --git a/llvm/lib/Target/LoongArch/LoongArch.td b/llvm/lib/Target/LoongArch/LoongArch.td
index ddb27dc6404fa8..c1bd94862b4e5e 100644
--- a/llvm/lib/Target/LoongArch/LoongArch.td
+++ b/llvm/lib/Target/LoongArch/LoongArch.td
@@ -128,30 +128,41 @@ include "LoongArchInstrInfo.td"
 // LoongArch processors supported.
 //===----------------------------------------------------------------------===//
 
-def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>;
-def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit, FeatureUAL]>;
+def ProcessorFeatures {
+  list<SubtargetFeature> LA32G    = [Feature32Bit];
+  list<SubtargetFeature> LA64G    = [Feature64Bit,
+                                     FeatureUAL];
+  list<SubtargetFeature> LA64GD   = [Feature64Bit,
+                                     FeatureUAL,
+                                     FeatureBasicD];
+  list<SubtargetFeature> LA64V1_0 = [Feature64Bit,
+                                     FeatureUAL,
+                                     FeatureExtLASX,
+                                     FeatureExtLVZ,
+                                     FeatureExtLBT];
+  list<SubtargetFeature> LA64V1_1 = [Feature64Bit,
+                                     FeatureUAL,
+                                     FeatureExtLASX,
+                                     FeatureExtLVZ,
+                                     FeatureExtLBT,
+                                     FeatureFrecipe];
+}
+
+def : ProcessorModel<"generic-la32", NoSchedModel, ProcessorFeatures.LA32G>;
+def : ProcessorModel<"generic-la64", NoSchedModel, ProcessorFeatures.LA64G>;
 
 // Generic 64-bit processor with double-precision floating-point support.
-def : ProcessorModel<"loongarch64", NoSchedModel, [Feature64Bit,
-                                                   FeatureUAL,
-                                                   FeatureBasicD]>;
+def : ProcessorModel<"loongarch64", NoSchedModel, ProcessorFeatures.LA64GD>;
 
 // Support generic for compatibility with other targets. The triple will be used
 // to change to the appropriate la32/la64 version.
 def : ProcessorModel<"generic", NoSchedModel, []>;
 
-def : ProcessorModel<"la464", NoSchedModel, [Feature64Bit,
-                                             FeatureUAL,
-                                             FeatureExtLASX,
-                                             FeatureExtLVZ,
-                                             FeatureExtLBT]>;
-
-def : ProcessorModel<"la664", NoSchedModel, [Feature64Bit,
-                                             FeatureUAL,
-                                             FeatureExtLASX,
-                                             FeatureExtLVZ,
-                                             FeatureExtLBT,
-                                             FeatureFrecipe]>;
+def : ProcessorModel<"la464", NoSchedModel, ProcessorFeatures.LA64V1_0>;
+def : ProcessorModel<"la64v1.0", NoSchedModel, ProcessorFeatures.LA64V1_0>;
+
+def : ProcessorModel<"la664", NoSchedModel, ProcessorFeatures.LA64V1_1>;
+def : ProcessorModel<"la64v1.1", NoSchedModel, ProcessorFeatures.LA64V1_1>;
 
 //===----------------------------------------------------------------------===//
 // Define the LoongArch target.
diff --git a/llvm/test/CodeGen/LoongArch/cpus.ll b/llvm/test/CodeGen/LoongArch/cpus.ll
index be3e05e394ff9a..aa5a81411a2d71 100644
--- a/llvm/test/CodeGen/LoongArch/cpus.ll
+++ b/llvm/test/CodeGen/LoongArch/cpus.ll
@@ -4,6 +4,8 @@
 ; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=loongarch64 2>&1 | FileCheck %s
 ; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=la464 2>&1 | FileCheck %s
 ; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=la664 2>&1 | FileCheck %s
+; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=la64v1.0 2>&1 | FileCheck %s
+; RUN: llc < %s --mtriple=loongarch64 -mattr=+d --mcpu=la64v1.1 2>&1 | FileCheck %s
 ; RUN: llc < %s --mtriple=loongarch64 -mattr=+d 2>&1 | FileCheck %s
 
 ; CHECK-NOT: {{.*}} is not a recognized processor for this target
@@ -23,3 +25,11 @@ define void @tune_cpu_la464() "tune-cpu"="la464" {
 define void @tune_cpu_la664() "tune-cpu"="la664" {
   ret void
 }
+
+define void @tune_cpu_la64v1_0() "tune-cpu"="la64v1.0" {
+  ret void
+}
+
+define void @tune_cpu_la64v1_1() "tune-cpu"="la64v1.1" {
+  ret void
+}

Footnotes

  1. https://github.com/loongson/la-toolchain-conventions?tab=readme-ov-file#list

Copy link
Contributor

@xen0n xen0n left a comment

Choose a reason for hiding this comment

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

While the changes here are good, I think it may be a good idea to also make the generic target to support FP and LSX (but not LASX), as per the recommended general computing baseline by Loongson. This is tangential to the issue at hand though, and we can do it in a separate PR if you agree. (I'm surprised to realize that generic does not support FP but the equally generic-sounding loongarch64 does -- this is very confusing and I always struggle to remember these details, even to this day.)

@heiher
Copy link
Member Author

heiher commented Oct 15, 2024

CLOSE: Internal reviewers believe that this change will make the -mtune value in Clang inconsistent with the la-toolchain-convention.

The changes to generic will be addressed in another PR.

@heiher heiher closed this Oct 15, 2024
@heiher heiher deleted the la64v1-proc-models branch October 15, 2024 12:00
Ami-zhang added a commit to Ami-zhang/llvm-project that referenced this pull request Oct 23, 2024
This commit makes the `generic` target to support FP and LSX, as
discussed in llvm#110211. Thereby, it allows 128-bit vector to be enabled
by default in the loongarch64 backend.
@xen0n
Copy link
Contributor

xen0n commented Oct 23, 2024

BTW, what are the plans for adding -march=la64v1.{0,1} eventually for feature parity with GCC?

@heiher
Copy link
Member Author

heiher commented Oct 23, 2024

BTW, what are the plans for adding -march=la64v1.{0,1} eventually for feature parity with GCC?

#100057

Ami-zhang added a commit to Ami-zhang/llvm-project that referenced this pull request Oct 24, 2024
This commit makes the `generic` target to support FP and LSX, as
discussed in llvm#110211. Thereby, it allows 128-bit vector to be enabled
by default in the loongarch64 backend.
Ami-zhang added a commit to Ami-zhang/llvm-project that referenced this pull request Oct 25, 2024
This commit makes the `generic` target to support FP and LSX, as
discussed in llvm#110211. Thereby, it allows 128-bit vector to be enabled
by default in the loongarch64 backend.
Ami-zhang added a commit that referenced this pull request Oct 31, 2024
This commit makes the `generic` target to support FP and LSX, as
discussed in #110211. Thereby, it allows 128-bit vector to be enabled by
default in the loongarch64 backend.
smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
)

This commit makes the `generic` target to support FP and LSX, as
discussed in llvm#110211. Thereby, it allows 128-bit vector to be enabled by
default in the loongarch64 backend.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
)

This commit makes the `generic` target to support FP and LSX, as
discussed in llvm#110211. Thereby, it allows 128-bit vector to be enabled by
default in the loongarch64 backend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants