[PATCH] D45344: Fold malloc + memset to calloc even for llvm.memset
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 5 17:41:40 PDT 2018
xbolva00 created this revision.
xbolva00 added reviewers: dlj, ab, spatel, dblaikie.
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
https://reviews.llvm.org/D45344
Files:
SimplifyLibCalls.cpp
Index: SimplifyLibCalls.cpp
===================================================================
--- SimplifyLibCalls.cpp
+++ SimplifyLibCalls.cpp
@@ -840,12 +840,8 @@
if (!FillValue || FillValue->getZExtValue() != 0)
return nullptr;
- // TODO: We should handle the case where the malloc has more than one use.
- // This is necessary to optimize common patterns such as when the result of
- // the malloc is checked against null or when a memset intrinsic is used in
- // place of a memset library call.
auto *Malloc = dyn_cast<CallInst>(Memset->getArgOperand(0));
- if (!Malloc || !Malloc->hasOneUse())
+ if (!Malloc)
return nullptr;
// Is the inner call really malloc()?
@@ -2219,7 +2215,8 @@
return optimizeLog(CI, Builder);
case Intrinsic::sqrt:
return optimizeSqrt(CI, Builder);
- // TODO: Use foldMallocMemset() with memset intrinsic.
+ case Intrinsic::memset:
+ return foldMallocMemset(CI, Builder, *TLI);
default:
return nullptr;
}
@@ -2393,7 +2390,8 @@
Value *FortifiedLibCallSimplifier::optimizeMemSetChk(CallInst *CI,
IRBuilder<> &B) {
- // TODO: Try foldMallocMemset() here.
+ if (auto *Calloc = foldMallocMemset(CI, B, *TLI))
+ return Calloc;
if (isFortifiedCallFoldable(CI, 3, 2, false)) {
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45344.141247.patch
Type: text/x-patch
Size: 1425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180406/aea6f49c/attachment.bin>
More information about the llvm-commits
mailing list