[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:43:45 PDT 2018
xbolva00 updated this revision to Diff 169896.
xbolva00 added a comment.
And I expect this will be noisy in tests
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,24 @@
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 void setNonNullParam(CallInst *CI, unsigned ArgNo) {
+ if (!CI->paramHasAttr(ArgNo, Attribute::NonNull))
+ CI->addParamAttr(ArgNo, Attribute::NonNull);
+}
+
//===----------------------------------------------------------------------===//
// 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 +234,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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53342.169896.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181016/1370e563/attachment.bin>
More information about the llvm-commits
mailing list