diff options
-rw-r--r-- | llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/DeadStoreElimination/merge-stores.ll | 6 |
2 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 18cf3592556..6c7d311112a 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1172,7 +1172,8 @@ static bool eliminateDeadStores(BasicBlock &BB, AliasAnalysis *AA, 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 diff --git a/llvm/test/Transforms/DeadStoreElimination/merge-stores.ll b/llvm/test/Transforms/DeadStoreElimination/merge-stores.ll index 6bac3b741be..ff1bfaa4d3c 100644 --- a/llvm/test/Transforms/DeadStoreElimination/merge-stores.ll +++ b/llvm/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 |