Skip to content

[Clang][Driver][fveclib] Fix target parsing for -fveclib=AMDLIBM option #140544

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

Merged
merged 7 commits into from
May 20, 2025

Conversation

rohitaggarwal007
Copy link
Contributor

@rohitaggarwal007 rohitaggarwal007 commented May 19, 2025

The behavior of -fveclib=AMDLIBM should be similar to -fveclib=libmvec.
Example - Error message for unsupported target usage should be same.

We are handling the missed cases for -fveclib=AMDLIBM and aligning it to -fveclib=libmvec usage.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels May 19, 2025
@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-flang-driver
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Rohit Aggarwal (rohitaggarwal007)

Changes

Handle some cases for target parsing for -fveclib=AMDLIBM option


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

3 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1)
  • (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1)
  • (modified) clang/test/Driver/fveclib.c (+10)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index a08bdba99bfe0..4aefdb24af17b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5844,7 +5844,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
           Triple.getArch() != llvm::Triple::x86_64)
         D.Diag(diag::err_drv_unsupported_opt_for_target)
             << Name << Triple.getArchName();
-    } else if (Name == "libmvec") {
+    } else if (Name == "libmvec" || Name == "AMDLIBM") {
       if (Triple.getArch() != llvm::Triple::x86 &&
           Triple.getArch() != llvm::Triple::x86_64)
         D.Diag(diag::err_drv_unsupported_opt_for_target)
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 632027c4a944c..722431c999b95 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -935,6 +935,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
         llvm::StringSwitch<std::optional<StringRef>>(ArgVecLib->getValue())
             .Case("Accelerate", "Accelerate")
             .Case("libmvec", "LIBMVEC")
+            .Case("AMDLIBM", "AMDLIBM")
             .Case("MASSV", "MASSV")
             .Case("SVML", "SVML")
             .Case("SLEEF", "sleefgnuabi")
diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index 1235d08a3e139..5420555c36a2a 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -1,6 +1,7 @@
 // RUN: %clang -### -c -fveclib=none %s 2>&1 | FileCheck --check-prefix=CHECK-NOLIB %s
 // RUN: %clang -### -c -fveclib=Accelerate %s 2>&1 | FileCheck --check-prefix=CHECK-ACCELERATE %s
 // RUN: %clang -### -c --target=x86_64-unknown-linux-gnu -fveclib=libmvec %s 2>&1 | FileCheck --check-prefix=CHECK-libmvec %s
+// RUN: %clang -### -c --target=x86_64-unknown-linux-gnu -fveclib=AMDLIBM %s 2>&1 | FileCheck --check-prefix=CHECK-AMDLIBM %s
 // RUN: %clang -### -c -fveclib=MASSV %s 2>&1 | FileCheck --check-prefix=CHECK-MASSV %s
 // RUN: %clang -### -c -fveclib=Darwin_libsystem_m %s 2>&1 | FileCheck --check-prefix=CHECK-DARWIN_LIBSYSTEM_M %s
 // RUN: %clang -### -c --target=aarch64 -fveclib=SLEEF %s 2>&1 | FileCheck --check-prefix=CHECK-SLEEF %s
@@ -11,6 +12,7 @@
 // CHECK-NOLIB: "-fveclib=none"
 // CHECK-ACCELERATE: "-fveclib=Accelerate"
 // CHECK-libmvec: "-fveclib=libmvec"
+// CHECK-AMDLIBM: "-fveclib=AMDLIBM"
 // CHECK-MASSV: "-fveclib=MASSV"
 // CHECK-DARWIN_LIBSYSTEM_M: "-fveclib=Darwin_libsystem_m"
 // CHECK-SLEEF: "-fveclib=SLEEF"
@@ -23,6 +25,7 @@
 // RUN: not %clang --target=x86 -c -fveclib=ArmPL %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
 // RUN: not %clang --target=aarch64 -c -fveclib=libmvec %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
 // RUN: not %clang --target=aarch64 -c -fveclib=SVML %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
+// RUN: not %clang --target=aarch64 -c -fveclib=AMDLIBM %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
 // CHECK-ERROR: unsupported option {{.*}} for target
 
 // RUN: %clang -fveclib=Accelerate %s -target arm64-apple-ios8.0.0 -### 2>&1 | FileCheck --check-prefix=CHECK-LINK %s
@@ -40,6 +43,9 @@
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=libmvec -flto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-LIBMVEC %s
 // CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC"
 
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=AMDLIBM -flto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-AMDLIBM %s
+// CHECK-LTO-AMDLIBM: "-plugin-opt=-vector-library=AMDLIBM"
+
 // RUN: %clang -### --target=powerpc64-unknown-linux-gnu -fveclib=MASSV -flto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-MASSV %s
 // CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
 
@@ -62,6 +68,10 @@
 // CHECK-ERRNO-LIBMVEC: "-fveclib=libmvec"
 // CHECK-ERRNO-LIBMVEC-SAME: "-fmath-errno"
 
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=AMDLIBM %s 2>&1 | FileCheck --check-prefix=CHECK-ERRNO-AMDLIBM %s
+// CHECK-ERRNO-AMDLIBM: "-fveclib=AMDLIBM"
+// CHECK-ERRNO-AMDLIBM-SAME: "-fmath-errno"
+
 // RUN: %clang -### --target=powerpc64-unknown-linux-gnu -fveclib=MASSV %s 2>&1 | FileCheck --check-prefix=CHECK-ERRNO-MASSV %s
 // CHECK-ERRNO-MASSV: "-fveclib=MASSV"
 // CHECK-ERRNO-MASSV-SAME: "-fmath-errno"

@llvmbot llvmbot added flang:driver flang Flang issues not falling into any other category labels May 19, 2025
@tarunprabhu
Copy link
Contributor

Is this doing a lot that is similar to #140533?

@rohitaggarwal007 rohitaggarwal007 changed the title [Clang][Flang][Driver] Fix target parsing for -fveclib=AMDLIBM option [Clang][Driver][fveclib] Fix target parsing for -fveclib=AMDLIBM option May 20, 2025
@rohitaggarwal007
Copy link
Contributor Author

Is this doing a lot that is similar to #140533?

Thank you for pointing out.

I have removed the changes related to Flang as it taken care in the mentioned patch

@llvmbot llvmbot added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label May 20, 2025
@rohitaggarwal007
Copy link
Contributor Author

@tarunprabhu @florianhumblot @alexey-bataev @RKSimon @phoebewang

Please review the pull request.
Thanks

@kiranktp
Copy link
Contributor

LGTM. Please wait for others to approve.

@RKSimon
Copy link
Collaborator

RKSimon commented May 20, 2025

@rohitaggarwal007 please can you edit the summary to briefly describe the fix

@rohitaggarwal007
Copy link
Contributor Author

@rohitaggarwal007 please can you edit the summary to briefly describe the fix

Done, Update the summary.

@rohitaggarwal007
Copy link
Contributor Author

@kiranktp @paulwalker-arm

Can you please merge this PR in main on my behalf?
I don't have the write permission.

Thank you

@paulwalker-arm paulwalker-arm merged commit 54f2b45 into llvm:main May 20, 2025
11 checks passed
@rohitaggarwal007 rohitaggarwal007 deleted the AMDLIBM branch May 20, 2025 12:40
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…on (llvm#140544)

The behavior of -fveclib=AMDLIBM should be similar to -fveclib=libmvec. 
Example - Error message for unsupported target usage should be same.

We are handling the missed cases for -fveclib=AMDLIBM and aligning it to
-fveclib=libmvec usage.

---------

Co-authored-by: Rohit Aggarwal <Rohit.Aggarwal@amd.com>
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 6, 2025
…on (llvm#140544)

The behavior of -fveclib=AMDLIBM should be similar to -fveclib=libmvec. 
Example - Error message for unsupported target usage should be same.

We are handling the missed cases for -fveclib=AMDLIBM and aligning it to
-fveclib=libmvec usage.

---------

Co-authored-by: Rohit Aggarwal <Rohit.Aggarwal@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category flang:driver flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants