[PATCH] D16337: [LibCallSimplifier] fold memset(malloc(x), 0, x) --> calloc(1, x)

Chad Rosier via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 22 13:41:24 PST 2016


mcrosier added a comment.

This looks to be in pretty good shape, but I wouldn't mind hearing other's opinions.


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:942
@@ +941,3 @@
+                               const TargetLibraryInfo &TLI) {
+  // This has to be a memset of zeros (bzero).
+  auto *FillValue = dyn_cast<ConstantInt>(Memset->getArgOperand(1));
----------------
Would it make more sense to check for calloc here?

if (!TLI.getLibFunc("calloc", Func) || !TLI.has(Func))
    return nullptr;

It would avoid some unnecessary work in the event we don't have calloc.  However, I assume we generally have calloc, so this might not be a great suggestion...  Just a suggestion that doesn't necessarily have to be acted upon.


http://reviews.llvm.org/D16337





More information about the llvm-commits mailing list