[PATCH] D53342: [SimplifyLibCalls][WIP] Mark known arguments with nonnull
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 16 14:39:20 PDT 2018
xbolva00 created this revision.
xbolva00 added a reviewer: efriedma.
Herald added a subscriber: llvm-commits.
Splitting patch https://reviews.llvm.org/D50039 to two parts.
Repository:
rL LLVM
https://reviews.llvm.org/D53342
Files:
lib/Transforms/Utils/SimplifyLibCalls.cpp
Index: lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -178,11 +178,25 @@
return true;
}
+template <typename T>
+static bool isPositiveSize(T *I, unsigned ArgNo) {
+ Value *Arg = I->getArgOperand(ArgNo);
+ return isa<ConstantInt>(Arg) && !cast<ConstantInt>(Arg)->isZero();
+}
+
+static CallInst *setNonNullParam(CallInst *CI, unsigned ArgNo) {
+ if (!CI->paramHasAttr(ArgNo, Attribute::NonNull))
+ CI->addParamAttr(ArgNo, Attribute::NonNull);
+ return nullptr;
+}
+
//===----------------------------------------------------------------------===//
// String and Memory Library Call Optimizations
//===----------------------------------------------------------------------===//
Value *LibCallSimplifier::optimizeStrCat(CallInst *CI, IRBuilder<> &B) {
+ setNonNullParam(CI, 0);
+ setNonNullParam(CI, 1);
// Extract some information from the instruction
Value *Dst = CI->getArgOperand(0);
Value *Src = CI->getArgOperand(1);
@@ -221,6 +235,10 @@
}
Value *LibCallSimplifier::optimizeStrNCat(CallInst *CI, IRBuilder<> &B) {
+ if (isPositiveSize(CI, 2)) {
+ setNonNullParam(CI, 0);
+ setNonNullParam(CI, 1);
+ }
// Extract some information from the instruction.
Value *Dst = CI->getArgOperand(0);
Value *Src = CI->getArgOperand(1);
@@ -597,6 +615,9 @@
}
Value *LibCallSimplifier::optimizeStrLen(CallInst *CI, IRBuilder<> &B) {
+
+ if (Value *V = setNonNullParam())
+ CI->paramHasAttr(0, Attribute::NonNull)
return optimizeStringLength(CI, B, 8);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53342.169894.patch
Type: text/x-patch
Size: 1660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181016/211dc7c1/attachment.bin>
More information about the llvm-commits
mailing list