[PATCH] D45344: Fold malloc + memset to calloc even for llvm.memset

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 5 17:53:53 PDT 2018


Test case?

On Thu, Apr 5, 2018 at 5:41 PM Dávid Bolvanský via Phabricator <
reviews at reviews.llvm.org> wrote:

> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180406/4d495602/attachment.html>


More information about the llvm-commits mailing list