aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2009-03-03 21:26:39 +0000
committerDale Johannesen <dalej@apple.com>2009-03-03 21:26:39 +0000
commit2c11fe22500fbd0563705e2ffe3810c061139f2a (patch)
tree7d4289d59f99c38cd21ebd66d4ac7365872be18f /lib
parent9e30964187536b8965248ab7b2d0f39b064981bd (diff)
downloadexternal_llvm-2c11fe22500fbd0563705e2ffe3810c061139f2a.zip
external_llvm-2c11fe22500fbd0563705e2ffe3810c061139f2a.tar.gz
external_llvm-2c11fe22500fbd0563705e2ffe3810c061139f2a.tar.bz2
When removing a store to an alloca that has only one
use, check also for the case where it has two uses, the other being a llvm.dbg.declare. This is needed so debug info doesn't affect codegen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65970 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp58
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp3
2 files changed, 49 insertions, 12 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index ad94aaa..64dd103 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -250,6 +250,8 @@ namespace {
Instruction *transformZExtICmp(ICmpInst *ICI, Instruction &CI,
bool DoXform = true);
bool WillNotOverflowSignedAdd(Value *LHS, Value *RHS);
+ DbgDeclareInst *hasOneUsePlusDeclare(Value *V);
+
public:
// InsertNewInstBefore - insert an instruction New before instruction Old
@@ -11403,6 +11405,23 @@ static bool equivalentAddressValues(Value *A, Value *B) {
return false;
}
+// If this instruction has two uses, one of which is a llvm.dbg.declare,
+// return the llvm.dbg.declare.
+DbgDeclareInst *InstCombiner::hasOneUsePlusDeclare(Value *V) {
+ if (!V->hasNUses(2))
+ return 0;
+ for (Value::use_iterator UI = V->use_begin(), E = V->use_end();
+ UI != E; ++UI) {
+ if (DbgDeclareInst *DI = dyn_cast<DbgDeclareInst>(UI))
+ return DI;
+ if (isa<BitCastInst>(UI) && UI->hasOneUse()) {
+ if (DbgDeclareInst *DI = dyn_cast<DbgDeclareInst>(UI->use_begin()))
+ return DI;
+ }
+ }
+ return 0;
+}
+
Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
Value *Val = SI.getOperand(0);
Value *Ptr = SI.getOperand(1);
@@ -11415,20 +11434,39 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
// If the RHS is an alloca with a single use, zapify the store, making the
// alloca dead.
- if (Ptr->hasOneUse() && !SI.isVolatile()) {
- if (isa<AllocaInst>(Ptr)) {
- EraseInstFromFunction(SI);
- ++NumCombined;
- return 0;
- }
-
- if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr))
- if (isa<AllocaInst>(GEP->getOperand(0)) &&
- GEP->getOperand(0)->hasOneUse()) {
+ // If the RHS is an alloca with a two uses, the other one being a
+ // llvm.dbg.declare, zapify the store and the declare, making the
+ // alloca dead. We must do this to prevent declare's from affecting
+ // codegen.
+ if (!SI.isVolatile()) {
+ if (Ptr->hasOneUse()) {
+ if (isa<AllocaInst>(Ptr)) {
EraseInstFromFunction(SI);
++NumCombined;
return 0;
}
+ if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) {
+ if (isa<AllocaInst>(GEP->getOperand(0))) {
+ if (GEP->getOperand(0)->hasOneUse()) {
+ EraseInstFromFunction(SI);
+ ++NumCombined;
+ return 0;
+ }
+ if (DbgDeclareInst *DI = hasOneUsePlusDeclare(GEP->getOperand(0))) {
+ EraseInstFromFunction(*DI);
+ EraseInstFromFunction(SI);
+ ++NumCombined;
+ return 0;
+ }
+ }
+ }
+ }
+ if (DbgDeclareInst *DI = hasOneUsePlusDeclare(Ptr)) {
+ EraseInstFromFunction(*DI);
+ EraseInstFromFunction(SI);
+ ++NumCombined;
+ return 0;
+ }
}
// Attempt to improve the alignment.
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 5f9a8b5..2887bdc 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -540,8 +540,7 @@ void llvm::CopyPrecedingStopPoint(Instruction *I,
if (I != I->getParent()->begin()) {
BasicBlock::iterator BBI = I; --BBI;
if (DbgStopPointInst *DSPI = dyn_cast<DbgStopPointInst>(BBI)) {
- DbgStopPointInst *newDSPI =
- reinterpret_cast<DbgStopPointInst*>(DSPI->clone());
+ CallInst *newDSPI = DSPI->clone();
newDSPI->insertBefore(InsertPos);
}
}