[DSE] Eliminate noop store even through has clobbering between LoadI and StoreI
authorluxufan <luxufan@iscas.ac.cn>
Wed, 24 Aug 2022 13:51:58 +0000 (13:51 +0000)
committerluxufan <luxufan@iscas.ac.cn>
Fri, 2 Sep 2022 06:37:41 +0000 (06:37 +0000)
commitcd8f3e75813995c1d2da35370ffcf5af3aff9c2f
treefb79e679e01d4e1246940b2b8d39e9f3fb171c58
parentacce4241111e3087319048b3d3aebab150c761c2
[DSE] Eliminate noop store even through has clobbering between LoadI and StoreI

For noop store of the form of LoadI and StoreI,
An invariant should be kept is that the memory state of the related
MemoryLoc before LoadI is the same as before StoreI.
For this example:
```
define void @pr49927(i32* %q, i32* %p) {
  %v = load i32, i32* %p, align 4
  store i32 %v, i32* %q, align 4
  store i32 %v, i32* %p, align 4
  ret void
}
```
Here the definition of the store's destination is different with the
definition of the load's destination, which it seems that the
invariant mentioned above is broken. But the definition of the
store's destination would write a value that is LoadI, actually, the
invariant is still kept. So we can safely ignore it.

Differential Revision: https://reviews.llvm.org/D132657
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll