From 771594b9ab02241dec7c254f490eb701b62de070 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 30 Jan 2018 13:53:59 +0000 Subject: [PATCH] [DSE] make sure memory is not modified before partial store merging (PR36129) We missed a critical check in 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 Differential Revision: https://reviews.llvm.org/D42663 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323759 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/DeadStoreElimination.cpp | 3 ++- test/Transforms/DeadStoreElimination/merge-stores.ll | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 18cf3592556..6c7d311112a 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1172,7 +1172,8 @@ static bool eliminateDeadStores(BasicBlock &BB, AliasAnalysis *AA, auto *Earlier = dyn_cast(DepWrite); auto *Later = dyn_cast(Inst); if (Earlier && isa(Earlier->getValueOperand()) && - Later && isa(Later->getValueOperand())) { + Later && isa(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 diff --git a/test/Transforms/DeadStoreElimination/merge-stores.ll b/test/Transforms/DeadStoreElimination/merge-stores.ll index 6bac3b741be..ff1bfaa4d3c 100644 --- a/test/Transforms/DeadStoreElimination/merge-stores.ll +++ b/test/Transforms/DeadStoreElimination/merge-stores.ll @@ -186,12 +186,14 @@ define void @PR34074(i32* %x, i64* %y) { 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 -- 2.11.0