Skip to content

Conversation

@Ami-zhang
Copy link
Contributor

@Ami-zhang Ami-zhang commented Aug 14, 2025

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

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" backend:loongarch labels Aug 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 14, 2025

@llvm/pr-subscribers-backend-loongarch

@llvm/pr-subscribers-clang

Author: None (Ami-zhang)

Changes

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.


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

2 Files Affected:

  • (modified) clang/lib/Basic/Targets/LoongArch.cpp (+6-1)
  • (added) clang/test/CodeGen/LoongArch/targetattr-lasx.c (+16)
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
new file mode 100644
index 0000000000000..28b06605289a8
--- /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 {{.*}}"}
+//.

Comment on lines 463 to 468
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (Value == "lasx") {
Ret.Features.push_back("+lasx");
Ret.Features.push_back("+lsx");
} else {
Ret.Features.push_back("+" + Value.str());
}
Ret.Features.push_back("+" + Value.str());
if (Value == "lasx")
Ret.Features.push_back("+lsx");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplify.

Copy link
Contributor

@SixWeining SixWeining left a comment

Choose a reason for hiding this comment

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

LGTM

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 llvm#149512.
@Ami-zhang Ami-zhang merged commit a1b6e7f into llvm:main Aug 15, 2025
9 checks passed
@azuresky01
Copy link

Can it be backported to LLVM 21?

@Ami-zhang
Copy link
Contributor Author

Can it be backported to LLVM 21?

Yes.

@Ami-zhang
Copy link
Contributor Author

/cherry-pick 793a6b4 a1b6e7f

@llvmbot
Copy link
Member

llvmbot commented Aug 15, 2025

/pull-request #153739

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Aug 15, 2025
@Ami-zhang Ami-zhang deleted the lasx branch August 18, 2025 01:41
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 18, 2025
…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 llvm#149512.

Depends on llvm#153541

(cherry picked from commit a1b6e7f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:loongarch clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

Development

Successfully merging this pull request may close these issues.

LoongArch: __attribute__((target("lasx"))) does not imply LSX

4 participants