[PATCH] D115904: [DSE] Remove calls with known writes to dead memory

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 16 13:44:29 PST 2021


reames created this revision.
reames added reviewers: nikic, anna.
Herald added subscribers: bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.

The majority of this change is sinking logic from instcombine into MemoryLocation such that it can be generically reused.  If we have a call with a single analyzable write to an argument, we can treat that as-if it were a store of unknown size.

Merging the code in this was unblocks DSE in the store to dead memory code paths.  In theory, it should also enable classic DSE of such calls, but the code appears to not know how to use object sizes to refine unknown access bounds (yet).

In addition, this does make the isAllocRemovable path slightly stronger by reusing the libfunc and additional intrinsics bits which are already in getForDest.

A couple ideas for follow up (which I don't plan to do):

- The more I look at this, the more I'm starting to think the capture handling is conservative.  It feels like the write and no-return handling should be enough to disallow capture in the problematic cases.  Maybe we can relax this?  Or adjust inference rules to simply infer?
- We should be able to use known object size info in DSE per the added test cases.
- We should be able to remove empty lifetime start/end ranges in DSE, and thus kill off remaining alloca uses.  Today, this will take another instcombine run.  Adding the DSE support is most useful when we have two distinct live ranges, one live and one dead.  DSE can recognize the dead one cheaply (even if large), where instcombine really can't.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115904

Files:
  llvm/include/llvm/Analysis/MemoryLocation.h
  llvm/lib/Analysis/MemoryLocation.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115904.394980.patch
Type: text/x-patch
Size: 17163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211216/2db81fc4/attachment.bin>


More information about the llvm-commits mailing list