aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/TargetLibraryInfo.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2022-12-20 11:37:51 -0800
committerCraig Topper <craig.topper@sifive.com>2022-12-20 11:47:04 -0800
commit9b2fecec406d6a6bcda9fbb9251db2ae202c7400 (patch)
tree40433f55df6c4f2b9bf1a2e2ab389caf97606cb1 /llvm/lib/Analysis/TargetLibraryInfo.cpp
parent3beb05417086443ad3314e7008090256b96741a2 (diff)
downloadllvm-9b2fecec406d6a6bcda9fbb9251db2ae202c7400.zip
llvm-9b2fecec406d6a6bcda9fbb9251db2ae202c7400.tar.gz
llvm-9b2fecec406d6a6bcda9fbb9251db2ae202c7400.tar.bz2
[BuildLibCalls][RISCV] Sign extend return value of bcmp on riscv64.
riscv64 wants callees to sign extend signed and unsigned int returns. The caller can use this to avoid a sign extend if the result is used by a comparison since riscv64 only has 64-bit compares. InstCombine/SimplifyLibCalls aggressively turn memcmps that are only used by an icmp eq 0 into bcmp, but we lose the signext attribute that would have been present on the memcmp. This causes an unneeded sext.w in the generated assembly. This looks even sillier if bcmp is implemented alias to memcmp. In that case, not only did we not get any savings by using bcmp, we added an instruction. This probably applies to other functions, this just happens to be the one I noticed so far. See also the discussion here https://discourse.llvm.org/t/can-we-preserve-signext-return-attribute-when-converting-memcmp-to-bcmp/67126 Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D139901
Diffstat (limited to 'llvm/lib/Analysis/TargetLibraryInfo.cpp')
-rw-r--r--llvm/lib/Analysis/TargetLibraryInfo.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 270fa9c..35811f7 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -169,7 +169,7 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_fgets_unlocked);
bool ShouldExtI32Param = false, ShouldExtI32Return = false,
- ShouldSignExtI32Param = false;
+ ShouldSignExtI32Param = false, ShouldSignExtI32Return = false;
// PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
// returns corresponding to C-level ints and unsigned ints.
if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
@@ -182,9 +182,15 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
if (T.isMIPS() || T.isRISCV64()) {
ShouldSignExtI32Param = true;
}
+ // riscv64 needs signext on i32 returns corresponding to both signed and
+ // unsigned ints.
+ if (T.isRISCV64()) {
+ ShouldSignExtI32Return = true;
+ }
TLI.setShouldExtI32Param(ShouldExtI32Param);
TLI.setShouldExtI32Return(ShouldExtI32Return);
TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
+ TLI.setShouldSignExtI32Return(ShouldSignExtI32Return);
// Let's assume by default that the size of int is 32 bits, unless the target
// is a 16-bit architecture because then it most likely is 16 bits. If that
@@ -882,6 +888,7 @@ TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
: CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
ShouldExtI32Return(TLI.ShouldExtI32Return),
ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
+ ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
SizeOfInt(TLI.SizeOfInt) {
memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
VectorDescs = TLI.VectorDescs;
@@ -893,6 +900,7 @@ TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
ShouldExtI32Param(TLI.ShouldExtI32Param),
ShouldExtI32Return(TLI.ShouldExtI32Return),
ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
+ ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
SizeOfInt(TLI.SizeOfInt) {
std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
AvailableArray);
@@ -905,6 +913,7 @@ TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoI
ShouldExtI32Param = TLI.ShouldExtI32Param;
ShouldExtI32Return = TLI.ShouldExtI32Return;
ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
+ ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
SizeOfInt = TLI.SizeOfInt;
memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
return *this;
@@ -915,6 +924,7 @@ TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&
ShouldExtI32Param = TLI.ShouldExtI32Param;
ShouldExtI32Return = TLI.ShouldExtI32Return;
ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
+ ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
SizeOfInt = TLI.SizeOfInt;
std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
AvailableArray);