[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:52:42 PDT 2018
xbolva00 updated this revision to Diff 169897.
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,30 @@
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 bool setNonNullParam(CallInst *CI, unsigned ArgNo) {
+ if (!CI->paramHasAttr(ArgNo, Attribute::NonNull)) {
+ CI->addParamAttr(ArgNo, Attribute::NonNull);
+ return true;
+ }
+ return false;
+}
+
//===----------------------------------------------------------------------===//
// String and Memory Library Call Optimizations
//===----------------------------------------------------------------------===//
Value *LibCallSimplifier::optimizeStrCat(CallInst *CI, IRBuilder<> &B) {
+ bool AttrChanged = false;
+ AttrChanged |= setNonNullParam(CI, 0);
+ AttrChanged |= setNonNullParam(CI, 1);
+ if (AttrChanged)
+ return CI;
// Extract some information from the instruction
Value *Dst = CI->getArgOperand(0);
Value *Src = CI->getArgOperand(1);
@@ -244,6 +263,13 @@
if (SrcLen == 0 || Len == 0)
return Dst;
+ // Non-zero length case
+ bool AttrChanged = false;
+ AttrChanged |= setNonNullParam(CI, 0);
+ AttrChanged |= setNonNullParam(CI, 1);
+ if (AttrChanged)
+ return CI;
+
// We don't optimize this case.
if (Len < SrcLen)
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53342.169897.patch
Type: text/x-patch
Size: 1547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181016/2012f486/attachment.bin>
More information about the llvm-commits
mailing list