https://github.com/Ami-zhang created 
https://github.com/llvm/llvm-project/pull/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.

>From 106481dbfb72200f9091f8eee4f36bbefb9bdc37 Mon Sep 17 00:00:00 2001
From: Ami-zhang <zhangli...@loongson.cn>
Date: Thu, 14 Aug 2025 11:08:26 +0800
Subject: [PATCH 1/2] [NFC] Precommit test for issue #149512

---
 clang/test/CodeGen/LoongArch/targetattr-lasx.c | 16 ++++++++++++++++
 1 file changed, 16 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..826180c73120f
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/targetattr-lasx.c
@@ -0,0 +1,16 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals all --version 5
+// RUN: %clang_cc1 -triple loongarch64 -target-feature -lsx -emit-llvm %s -o - 
| FileCheck %s
+
+__attribute__((target("lasx")))
+// CHECK-LABEL: define dso_local void @testlasx(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    ret void
+//
+void testlasx() {}
+//.
+// CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+64bit,+lasx,-lsx" }
+//.
+// CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
+//.

>From 1a3f3afb47733b705f8a80fcb2d894e81cb12a5d Mon Sep 17 00:00:00 2001
From: Ami-zhang <zhangli...@loongson.cn>
Date: Thu, 14 Aug 2025 14:34:04 +0800
Subject: [PATCH 2/2] [clang][LoongArch] Ensure `target("lasx")` implies LSX
 support

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.
---
 clang/lib/Basic/Targets/LoongArch.cpp          | 7 ++++++-
 clang/test/CodeGen/LoongArch/targetattr-lasx.c | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index f6915df1520b7..33001b23f48c6 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -460,7 +460,12 @@ LoongArchTargetInfo::parseTargetAttr(StringRef Features) 
const {
       break;
 
     case AttrFeatureKind::Feature:
-      Ret.Features.push_back("+" + Value.str());
+      if (Value == "lasx") {
+        Ret.Features.push_back("+lasx");
+        Ret.Features.push_back("+lsx");
+      } else {
+        Ret.Features.push_back("+" + Value.str());
+      }
       break;
     }
   }
diff --git a/clang/test/CodeGen/LoongArch/targetattr-lasx.c 
b/clang/test/CodeGen/LoongArch/targetattr-lasx.c
index 826180c73120f..28b06605289a8 100644
--- a/clang/test/CodeGen/LoongArch/targetattr-lasx.c
+++ b/clang/test/CodeGen/LoongArch/targetattr-lasx.c
@@ -9,7 +9,7 @@ __attribute__((target("lasx")))
 //
 void testlasx() {}
 //.
-// CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+64bit,+lasx,-lsx" }
+// CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+64bit,+lasx,+lsx" }
 //.
 // CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
 // CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to