Skip to content

Commit 756f489

Browse files
mintsukitru
authored andcommitted
LoongArch: Improve detection of valid TripleABI (#147952)
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 ``` (cherry picked from commit 9ed8816)
1 parent aaaa542 commit 756f489

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ static ABI getTripleABI(const Triple &TT) {
5252
bool Is64Bit = TT.isArch64Bit();
5353
ABI TripleABI;
5454
switch (TT.getEnvironment()) {
55+
case llvm::Triple::EnvironmentType::UnknownEnvironment:
56+
TripleABI = ABI_Unknown;
57+
break;
5558
case llvm::Triple::EnvironmentType::GNUSF:
5659
case llvm::Triple::EnvironmentType::MuslSF:
5760
TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
@@ -96,7 +99,7 @@ ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits,
9699

97100
// 1. If the '-target-abi' is valid, use it.
98101
if (IsABIValidForFeature(ArgProvidedABI)) {
99-
if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
102+
if (IsABIValidForFeature(TripleABI) && ArgProvidedABI != TripleABI)
100103
errs()
101104
<< "warning: triple-implied ABI conflicts with provided target-abi '"
102105
<< ABIName << "', using target-abi\n";
@@ -164,10 +167,7 @@ ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits,
164167
return Is64Bit ? ABI_LP64F : ABI_ILP32F;
165168
return Is64Bit ? ABI_LP64S : ABI_ILP32S;
166169
};
167-
if (ABIName.empty())
168-
errs() << "warning: the triple-implied ABI is invalid, ignoring and using "
169-
"feature-implied ABI\n";
170-
else
170+
if (!ABIName.empty())
171171
errs() << "warning: both target-abi and the triple-implied ABI are "
172172
"invalid, ignoring and using feature-implied ABI\n";
173173
return checkABIStandardized(GetFeatureABI());

llvm/test/CodeGen/LoongArch/target-abi-from-triple-edge-cases.ll

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
; NO-WARNING-NOT: warning: triple-implied ABI conflicts with provided target-abi 'lp64d', using target-abi
2525

2626
;; Check that ILP32-on-LA64 and LP64-on-LA32 combinations are handled properly.
27-
; RUN: llc --mtriple=loongarch64 --target-abi=ilp32d --mattr=+d < %s 2>&1 \
27+
; RUN: llc --mtriple=loongarch64-linux-gnu --target-abi=ilp32d --mattr=+d < %s 2>&1 \
2828
; RUN: | FileCheck %s --check-prefixes=LP64D,32ON64
29-
; RUN: llc --mtriple=loongarch32 --target-abi=lp64d --mattr=+d < %s 2>&1 \
29+
; RUN: llc --mtriple=loongarch32-linux-gnu --target-abi=lp64d --mattr=+d < %s 2>&1 \
3030
; RUN: | FileCheck %s --check-prefixes=ILP32D,64ON32
3131

3232
; 32ON64: warning: 32-bit ABIs are not supported for 64-bit targets, ignoring and using triple-implied ABI
@@ -49,12 +49,6 @@
4949

5050
; LP64D-LP64F-NOF: warning: both target-abi and the triple-implied ABI are invalid, ignoring and using feature-implied ABI
5151

52-
;; Check that triple-implied ABI are invalid, use feature-implied ABI
53-
; RUN: llc --mtriple=loongarch64 --mattr=-f < %s 2>&1 \
54-
; RUN: | FileCheck %s --check-prefixes=LP64S,LP64D-NONE-NOF
55-
56-
; LP64D-NONE-NOF: warning: the triple-implied ABI is invalid, ignoring and using feature-implied ABI
57-
5852
define float @f(float %a) {
5953
; ILP32D-LABEL: f:
6054
; ILP32D: # %bb.0:

0 commit comments

Comments
 (0)