[PATCH] D42663: [DSE] make sure memory is not modified before partial store merging (PR36129)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 15:08:17 PST 2018


spatel created this revision.
spatel added reviewers: dmgreen, filcab, RKSimon, hfinkel.
Herald added a subscriber: mcrosier.

We missed a critical check in https://reviews.llvm.org/D30703. We must make sure that no intermediate store is sitting between the stores that we want to merge.

This should fix:
https://bugs.llvm.org/show_bug.cgi?id=36129

Thanks to Dave Green for the reduction and suggestion.


https://reviews.llvm.org/D42663

Files:
  lib/Transforms/Scalar/DeadStoreElimination.cpp
  test/Transforms/DeadStoreElimination/merge-stores.ll


Index: test/Transforms/DeadStoreElimination/merge-stores.ll
===================================================================
--- test/Transforms/DeadStoreElimination/merge-stores.ll
+++ test/Transforms/DeadStoreElimination/merge-stores.ll
@@ -186,12 +186,14 @@
   ret void
 }
 
-; FIXME: We can't eliminate the last store because P and Q may alias.
+; We can't eliminate the last store because P and Q may alias.
 
 define void @PR36129(i32* %P, i32* %Q) {
 ; CHECK-LABEL: @PR36129(
-; CHECK-NEXT:    store i32 3, i32* [[P:%.*]]
+; CHECK-NEXT:    store i32 1, i32* [[P:%.*]]
+; CHECK-NEXT:    [[P2:%.*]] = bitcast i32* [[P]] to i8*
 ; CHECK-NEXT:    store i32 2, i32* [[Q:%.*]]
+; CHECK-NEXT:    store i8 3, i8* [[P2]]
 ; CHECK-NEXT:    ret void
 ;
   store i32 1, i32* %P
Index: lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1172,7 +1172,8 @@
           auto *Earlier = dyn_cast<StoreInst>(DepWrite);
           auto *Later = dyn_cast<StoreInst>(Inst);
           if (Earlier && isa<ConstantInt>(Earlier->getValueOperand()) &&
-              Later && isa<ConstantInt>(Later->getValueOperand())) {
+              Later && isa<ConstantInt>(Later->getValueOperand()) &&
+              memoryIsNotModifiedBetween(Earlier, Later, AA)) {
             // If the store we find is:
             //   a) partially overwritten by the store to 'Loc'
             //   b) the later store is fully contained in the earlier one and


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42663.131880.patch
Type: text/x-patch
Size: 1596 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180129/3150da99/attachment.bin>


More information about the llvm-commits mailing list