From 7ebba512c3417f0eb52ab68b39831e3a85105d66 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Thu, 1 Nov 2007 05:29:16 +0000 Subject: [PATCH] Fix test/Transforms/DeadStoreElimination/PartialStore.ll, which had been silently failing because of an incorrect run line for some time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43605 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/DeadStoreElimination.cpp | 16 ++++++++++++---- .../DeadStoreElimination/PartialStore.ll | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 1e5381db9af..2e1d9ade0a7 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -63,14 +63,18 @@ namespace { /// from allocas, it is safe to ignore GEP indices, since /// either the store will be in the alloca, and thus dead, /// or beyond the end of the alloca, and thus undefined. - void TranslatePointerBitCasts(Value*& v) { + void TranslatePointerBitCasts(Value*& v, bool zeroGepsOnly = false) { assert(isa(v->getType()) && "Translating a non-pointer type?"); while (true) { if (BitCastInst* C = dyn_cast(v)) v = C->getOperand(0); else if (GetElementPtrInst* G = dyn_cast(v)) - v = G->getOperand(0); + if (!zeroGepsOnly || G->hasAllZeroIndices()) { + v = G->getOperand(0); + } else { + break; + } else break; } @@ -95,7 +99,8 @@ FunctionPass *llvm::createDeadStoreEliminationPass() { return new DSE(); } bool DSE::runOnBasicBlock(BasicBlock &BB) { MemoryDependenceAnalysis& MD = getAnalysis(); - + TargetData &TD = getAnalysis(); + // Record the last-seen store to this pointer DenseMap lastStore; // Record instructions possibly made dead by deleting a store @@ -119,6 +124,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) { } else pointer = cast(BBI)->getPointerOperand(); + TranslatePointerBitCasts(pointer, true); StoreInst*& last = lastStore[pointer]; bool deletedStore = false; @@ -130,7 +136,9 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) { while (dep != MemoryDependenceAnalysis::None && dep != MemoryDependenceAnalysis::NonLocal && isa(dep)) { - if (dep != last) { + if (dep != last || + TD.getTypeSize(last->getOperand(0)->getType()) > + TD.getTypeSize(BBI->getOperand(0)->getType())) { dep = MD.getDependency(BBI, dep); continue; } diff --git a/test/Transforms/DeadStoreElimination/PartialStore.ll b/test/Transforms/DeadStoreElimination/PartialStore.ll index bdc16dbcb8c..14b2b0d2708 100644 --- a/test/Transforms/DeadStoreElimination/PartialStore.ll +++ b/test/Transforms/DeadStoreElimination/PartialStore.ll @@ -1,5 +1,5 @@ ; RUN: llvm-upgrade < %s | llvm-as | opt -dse | llvm-dis | \ -; RUN: not grep {store sbyte} +; RUN: not grep {store i8} ; Ensure that the dead store is deleted in this case. It is wholely ; overwritten by the second store. int %test() {