[llvm-branch-commits] [clang] release/21.x: [clang][LoongArch] Ensure `target("lasx")` implies LSX support (#153542) (PR #153739)

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Aug 17 22:53:50 PDT 2025


https://github.com/tru updated https://github.com/llvm/llvm-project/pull/153739

>From 9bf61a610c095d9b04f663eb505d2da014a30433 Mon Sep 17 00:00:00 2001
From: Ami-zhang <zhanglimin at loongson.cn>
Date: Fri, 15 Aug 2025 09:15:15 +0800
Subject: [PATCH 1/2] [NFC] Precommit test for issue #149512 (#153541)

(cherry picked from commit 793a6b4fd402c929e04f9da407fe4491d5d9d22e)
---
 clang/test/CodeGen/LoongArch/targetattr-lasx.c | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 clang/test/CodeGen/LoongArch/targetattr-lasx.c

diff --git a/clang/test/CodeGen/LoongArch/targetattr-lasx.c b/clang/test/CodeGen/LoongArch/targetattr-lasx.c
new file mode 100644
index 0000000000000..f4857406180a2
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/targetattr-lasx.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple loongarch64 -target-feature -lsx -emit-llvm %s -o - | FileCheck %s
+
+__attribute__((target("lasx")))
+// CHECK: #[[ATTR0:[0-9]+]] {
+void testlasx() {}
+
+// CHECK: attributes #[[ATTR0]] = { {{.*}}"target-features"="+64bit,+lasx,-lsx"{{.*}} }

>From 08b57975566f96ff545401f7777afc37b19961f2 Mon Sep 17 00:00:00 2001
From: Ami-zhang <zhanglimin at loongson.cn>
Date: Fri, 15 Aug 2025 09:53:08 +0800
Subject: [PATCH 2/2] [clang][LoongArch] Ensure `target("lasx")` implies LSX
 support (#153542)

Currently, `__attribute__((target("lasx")))` does not automatically
enable LSX support, causing Clang to fail with `-mno-lsx`. Since
LASX depends on LSX, enabling LASX should implicitly enable LSX to
avoid clang error.

Fixes #149512.

Depends on #153541

(cherry picked from commit a1b6e7ff393533a5c4f3bdfd4efe5da106e2de2b)
---
 clang/lib/Basic/Targets/LoongArch.cpp          | 2 ++
 clang/test/CodeGen/LoongArch/targetattr-lasx.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp
index f6915df1520b7..8e29bb745734b 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -461,6 +461,8 @@ LoongArchTargetInfo::parseTargetAttr(StringRef Features) const {
 
     case AttrFeatureKind::Feature:
       Ret.Features.push_back("+" + Value.str());
+      if (Value == "lasx")
+        Ret.Features.push_back("+lsx");
       break;
     }
   }
diff --git a/clang/test/CodeGen/LoongArch/targetattr-lasx.c b/clang/test/CodeGen/LoongArch/targetattr-lasx.c
index f4857406180a2..56fd6573ed34c 100644
--- a/clang/test/CodeGen/LoongArch/targetattr-lasx.c
+++ b/clang/test/CodeGen/LoongArch/targetattr-lasx.c
@@ -4,4 +4,4 @@ __attribute__((target("lasx")))
 // CHECK: #[[ATTR0:[0-9]+]] {
 void testlasx() {}
 
-// CHECK: attributes #[[ATTR0]] = { {{.*}}"target-features"="+64bit,+lasx,-lsx"{{.*}} }
+// CHECK: attributes #[[ATTR0]] = { {{.*}}"target-features"="+64bit,+lasx,+lsx"{{.*}} }



More information about the llvm-branch-commits mailing list