[PATCH] D109280: [WIP][DSE] Memory intrinsics like memset, memcpy, memmove are removed if they are overwritten by a store in a loop

Daniil Seredkin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 4 13:45:10 PDT 2021


vdsered created this revision.
Herald added a subscriber: hiraditya.
vdsered requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

NOTE: This patch is still in progress

The patch would allow DSE to remove more instructions that overwrite a specific region of memory. The two examples below demonstrate what it means

1. memory intrinsic + loop



  memset(Ptr, 0, N * sizeof(type of Ptr));
  for (int i = 0; i < N; ++i)
       Ptr[i] = 1;



2. loop + loop



  for (int i = 0; i < N; ++i)
       Ptr[i] = 1;
  for (int i = 0; i < N; ++i)
       Ptr[i] = 1;

In both examples there is a region of memory that we write to twice. This patch concentrates on the first case.

DSE can actually remove instructions like memset when they all are in the same basic block <https://godbolt.org/z/vG6r6nz3s>, but it seems to be lack of ability to remove it when they are in different basic blocks <https://godbolt.org/z/ePETG8fK7> and even if it could optimize it, it would not help us with loops because, for example, it is not always possible to convert a loop to a memory intrinsic what LoopIdiomRecognize does and so on.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109280

Files:
  llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
  llvm/test/Transforms/DeadStoreElimination/loop-variant-store-and-dom-memory-intrinsic.ll
  llvm/test/Transforms/DeadStoreElimination/loop-variant-store-and-post-dom-memory-intrinsic.ll
  llvm/test/Transforms/DeadStoreElimination/loop-variant-store-negative-tests.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109280.370761.patch
Type: text/x-patch
Size: 56161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210904/58cd02cc/attachment.bin>


More information about the llvm-commits mailing list