[PATCH] D112313: [DSE] Optimize defining access of defs while walking upwards.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 27 03:27:44 PDT 2021


fhahn marked an inline comment as done.
fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp:1486
+              (OR == OW_Complete || OR == OW_MaybePartial))
+            KillingDef->setOptimized(CurrentDef);
+
----------------
nikic wrote:
> fhahn wrote:
> > nikic wrote:
> > > I think this is incorrect if KillingDef accesses multiple locations. Say you have a memcpy, then KillingLoc will point to the write location only, and that's the only one for which we will check aliasing. This means that the optimized access might look past a clobber of the read location.
> > But isn't the optimized access only for write clobbers? This is the part that is not really documented well, but going from the use in `getClobberingMemoryAccess` it looks like it should be the nearest dominating write clobber
> Yes, it's about write clobbers. The problem is that a MemoryDef may access multiple locations, and the optimized access is the nearest write clobber on any of those locations. Your code (unless I'm missing something) will only find clobbers to the write location of KillingDef, but not to any additional read locations it may have.
> 
> ```
> ; assuming p, q noalias
> write(p) <-- optimized access found by this implementation
> write(q) <-- correct optimized access
> memcpy(p, q)
> ```
You are right, I my thinking about mem-defs was a bit backwards, we also need to consider defs of the read access here. I updated the code to not optimize killing defs that also read from memory. With the current restriction to only support writing instructions with a single memory location that should guarantee that only defs which access a single location (KillingLoc) are optimized.

I added a test in 1a2a7cca3e43 which I think may be mis-optimized due to the issue you described, if we support eliminating redundant memcpys based on earlier memcpys.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112313/new/

https://reviews.llvm.org/D112313



More information about the llvm-commits mailing list