aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Paulsson <paulsson@linux.vnet.ibm.com>2022-04-05 09:55:43 +0200
committerJonas Paulsson <paulsson@linux.vnet.ibm.com>2022-04-05 10:29:42 +0200
commitdbb6a75fbb3679a03edf6f4bc7e7262f751b6dfc (patch)
tree122dcafd3876eb7419aa1c0fbb1881caa6d5feb8
parentdda366ed37cec7b2f7c96a47b1b32391b514d969 (diff)
downloadllvm-dbb6a75fbb3679a03edf6f4bc7e7262f751b6dfc.zip
llvm-dbb6a75fbb3679a03edf6f4bc7e7262f751b6dfc.tar.gz
llvm-dbb6a75fbb3679a03edf6f4bc7e7262f751b6dfc.tar.bz2
[LibCalls] Respect TLI.getExtAttrForI32Param() in inferLibFuncAttributes().
getExtAttrForI32Param() is the method to be used for determining the type of extension attribute (if any) that is to be added for a signed/unsigned argument. Previously, the SExt attribute was always added to the i32 ldexp* argument as it was expected to be ignored by targets not needing it. This patch now changes this so that it is only added for the targets that need it in the first place. Putchar() argument is now also extended as required by the target (SystemZ in the test), to fix the issue below. Many more libcalls will be handled similarly in a following patch. Fixes https://github.com/llvm/llvm-project/issues/54532. Differential Revision: https://reviews.llvm.org/D123030 Review: Eli Friedman
-rw-r--r--llvm/lib/Transforms/Utils/BuildLibCalls.cpp15
-rw-r--r--llvm/test/Transforms/InferFunctionAttrs/annotate.ll11
2 files changed, 17 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 8a0fe75..e8e7044 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -39,7 +39,7 @@ STATISTIC(NumInaccessibleMemOrArgMemOnly,
STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
-STATISTIC(NumSExtArg, "Number of arguments inferred as signext");
+STATISTIC(NumExtArg, "Number of arguments inferred as signext/zeroext.");
STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
@@ -147,11 +147,13 @@ static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
return true;
}
-static bool setSignExtendedArg(Function &F, unsigned ArgNo) {
- if (F.hasParamAttribute(ArgNo, Attribute::SExt))
+static bool setArgExtAttr(Function &F, unsigned ArgNo,
+ const TargetLibraryInfo &TLI, bool Signed = true) {
+ Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
+ if (ExtAttr == Attribute::None || F.hasParamAttribute(ArgNo, ExtAttr))
return false;
- F.addParamAttr(ArgNo, Attribute::SExt);
- ++NumSExtArg;
+ F.addParamAttr(ArgNo, ExtAttr);
+ ++NumExtArg;
return true;
}
@@ -829,6 +831,7 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
case LibFunc_putchar:
case LibFunc_putchar_unlocked:
Changed |= setRetAndArgsNoUndef(F);
+ Changed |= setArgExtAttr(F, 0, TLI);
Changed |= setDoesNotThrow(F);
return Changed;
case LibFunc_popen:
@@ -1049,7 +1052,7 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
case LibFunc_ldexp:
case LibFunc_ldexpf:
case LibFunc_ldexpl:
- Changed |= setSignExtendedArg(F, 1);
+ Changed |= setArgExtAttr(F, 1, TLI);
Changed |= setWillReturn(F);
return Changed;
case LibFunc_abs:
diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
index 1909d82..953798d 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -3,6 +3,7 @@
; RUN: opt < %s -mtriple=x86_64-apple-macosx10.8.0 -inferattrs -S | FileCheck --match-full-lines --check-prefixes=CHECK,CHECK-KNOWN,CHECK-NOLINUX,CHECK-OPEN,CHECK-DARWIN %s
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -inferattrs -S | FileCheck --match-full-lines --check-prefixes=CHECK,CHECK-KNOWN,CHECK-LINUX %s
; RUN: opt < %s -mtriple=nvptx -inferattrs -S | FileCheck --match-full-lines --check-prefixes=CHECK-NOLINUX,CHECK-NVPTX %s
+; RUN: opt < %s -mtriple=s390x-linux-gnu -inferattrs -S | FileCheck --check-prefixes=CHECK-SYSTEMZ %s
declare i32 @__nvvm_reflect(i8*)
; CHECK-NVPTX: declare noundef i32 @__nvvm_reflect(i8* noundef) [[NOFREE_NOUNWIND_READNONE:#[0-9]+]]
@@ -590,13 +591,15 @@ declare i64 @labs(i64)
; CHECK: declare noundef i32 @lchown(i8* nocapture noundef readonly, i32 noundef, i32 noundef) [[NOFREE_NOUNWIND]]
declare i32 @lchown(i8*, i32, i32)
-; CHECK: declare double @ldexp(double, i32 signext) [[NOFREE_WILLRETURN:#[0-9]+]]
+; CHECK: declare double @ldexp(double, i32) [[NOFREE_WILLRETURN:#[0-9]+]]
+; CHECK-SYSTEMZ: declare double @ldexp(double, i32 signext)
declare double @ldexp(double, i32)
-; CHECK: declare float @ldexpf(float, i32 signext) [[NOFREE_WILLRETURN]]
+; CHECK: declare float @ldexpf(float, i32) [[NOFREE_WILLRETURN]]
+; CHECK-SYSTEMZ: declare float @ldexpf(float, i32 signext)
declare float @ldexpf(float, i32)
-; CHECK: declare x86_fp80 @ldexpl(x86_fp80, i32 signext) [[NOFREE_WILLRETURN]]
+; CHECK: declare x86_fp80 @ldexpl(x86_fp80, i32) [[NOFREE_WILLRETURN]]
declare x86_fp80 @ldexpl(x86_fp80, i32)
; CHECK: declare i64 @llabs(i64) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
@@ -753,10 +756,12 @@ declare i32 @printf(i8*, ...)
declare i32 @putc(i32, %opaque*)
; CHECK: declare noundef i32 @putchar(i32 noundef) [[NOFREE_NOUNWIND]]
+; CHECK-SYSTEMZ: declare noundef i32 @putchar(i32 noundef signext)
declare i32 @putchar(i32)
; CHECK-KNOWN: declare noundef i32 @putchar_unlocked(i32 noundef) [[NOFREE_NOUNWIND]]
; CHECK-UNKNOWN: declare i32 @putchar_unlocked(i32){{$}}
+; CHECK-SYSTEMZ: declare noundef i32 @putchar_unlocked(i32 noundef signext)
declare i32 @putchar_unlocked(i32)
; CHECK: declare noundef i32 @puts(i8* nocapture noundef readonly) [[NOFREE_NOUNWIND]]