[llvm] LoongArch: Improve detection of valid TripleABI (PR #147952)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 15 21:49:59 PDT 2025


https://github.com/mintsuki updated https://github.com/llvm/llvm-project/pull/147952

>From 9e9bf0ecca54f3592d42ed81fa57d0f32808c7b9 Mon Sep 17 00:00:00 2001
From: Mintsuki <mintsuki at protonmail.com>
Date: Thu, 10 Jul 2025 14:37:07 +0200
Subject: [PATCH] LoongArch: Improve detection of valid TripleABI

If the environment is considered to be the triple component as a whole, so,
including the object format, if any, and if that is the intended behaviour,
then the loongarch64 function computeTargetABI() should be changed to not rely
on hasEnvironment(), but, rather, to check if there is a non-unknown
environment set.

Without this change, using a (ideally valid) target of
loongarch64-unknown-none-elf, with a manually specified ABI of lp64s, will
result in a completely superfluous warning:

  warning: triple-implied ABI conflicts with provided target-abi 'lp64s', using target-abi
---
 .../Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp  | 9 ++++++---
 .../LoongArch/target-abi-from-triple-edge-cases.ll       | 4 ++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
index 03ce004ed33a5..ff8a1274202b3 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
@@ -60,11 +60,14 @@ static ABI getTripleABI(const Triple &TT) {
   case llvm::Triple::EnvironmentType::MuslF32:
     TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
     break;
-  // Let the fallback case behave like {ILP32,LP64}D.
+  case llvm::Triple::EnvironmentType::GNU:
   case llvm::Triple::EnvironmentType::GNUF64:
-  default:
+  case llvm::Triple::EnvironmentType::Musl:
     TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
     break;
+  default:
+    TripleABI = ABI_Unknown;
+    break;
   }
   return TripleABI;
 }
@@ -96,7 +99,7 @@ ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits,
 
   // 1. If the '-target-abi' is valid, use it.
   if (IsABIValidForFeature(ArgProvidedABI)) {
-    if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
+    if (IsABIValidForFeature(TripleABI) && ArgProvidedABI != TripleABI)
       errs()
           << "warning: triple-implied ABI conflicts with provided target-abi '"
           << ABIName << "', using target-abi\n";
diff --git a/llvm/test/CodeGen/LoongArch/target-abi-from-triple-edge-cases.ll b/llvm/test/CodeGen/LoongArch/target-abi-from-triple-edge-cases.ll
index eb656ad94e28b..4fa2817bff32c 100644
--- a/llvm/test/CodeGen/LoongArch/target-abi-from-triple-edge-cases.ll
+++ b/llvm/test/CodeGen/LoongArch/target-abi-from-triple-edge-cases.ll
@@ -24,9 +24,9 @@
 ; NO-WARNING-NOT:  warning: triple-implied ABI conflicts with provided target-abi 'lp64d', using target-abi
 
 ;; Check that ILP32-on-LA64 and LP64-on-LA32 combinations are handled properly.
-; RUN: llc --mtriple=loongarch64 --target-abi=ilp32d --mattr=+d < %s 2>&1 \
+; RUN: llc --mtriple=loongarch64-linux-gnu --target-abi=ilp32d --mattr=+d < %s 2>&1 \
 ; RUN:   | FileCheck %s --check-prefixes=LP64D,32ON64
-; RUN: llc --mtriple=loongarch32 --target-abi=lp64d --mattr=+d < %s 2>&1 \
+; RUN: llc --mtriple=loongarch32-linux-gnu --target-abi=lp64d --mattr=+d < %s 2>&1 \
 ; RUN:   | FileCheck %s --check-prefixes=ILP32D,64ON32
 
 ; 32ON64: warning: 32-bit ABIs are not supported for 64-bit targets, ignoring and using triple-implied ABI



More information about the llvm-commits mailing list