aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2009-03-03 01:09:07 +0000
committerDale Johannesen <dalej@apple.com>2009-03-03 01:09:07 +0000
commitbd8e650876cc93952dde3120938271dbda6cbbb7 (patch)
tree507a6aae96bcd4fe35ebbd2f1d7ff5f8b6e7e3d4
parentcd11991203f2f8ca8b0c7bd920fa4e32b4f88e1d (diff)
When sinking an insn in InstCombine bring its debug
info with it. Don't count debug info insns against the scan maximum in FindAvailableLoadedValue (lest they affect codegen). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65910 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Transforms/Utils/BasicBlockUtils.h5
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp1
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp27
3 files changed, 31 insertions, 2 deletions
diff --git a/include/llvm/Transforms/Utils/BasicBlockUtils.h b/include/llvm/Transforms/Utils/BasicBlockUtils.h
index 429d3b6edc..a629b119bc 100644
--- a/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -60,6 +60,11 @@ void ReplaceInstWithInst(BasicBlock::InstListType &BIL,
//
void ReplaceInstWithInst(Instruction *From, Instruction *To);
+/// CopyPrecedingStopPoint - If I is immediately preceded by a StopPoint,
+/// make a copy of the stoppoint before InsertPos (presumably before copying
+/// or moving I).
+void CopyPrecedingStopPoint(Instruction *I, BasicBlock::iterator InsertPos);
+
/// FindAvailableLoadedValue - Scan the ScanBB block backwards (starting at the
/// instruction before ScanFrom) checking to see if we have the value at the
/// memory address *Ptr locally available within a small number of instructions.
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 7ddbb4ca7c..e0d3ac4d42 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -12374,6 +12374,7 @@ static bool TryToSinkInstruction(Instruction *I, BasicBlock *DestBlock) {
BasicBlock::iterator InsertPos = DestBlock->getFirstNonPHI();
+ CopyPrecedingStopPoint(I, InsertPos);
I->moveBefore(InsertPos);
++NumSunkInst;
return true;
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 7b633b2007..875de559b7 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -15,6 +15,7 @@
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
#include "llvm/Constant.h"
#include "llvm/Type.h"
#include "llvm/Analysis/AliasAnalysis.h"
@@ -471,11 +472,18 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
}
while (ScanFrom != ScanBB->begin()) {
+ // We must ignore debug info directives when counting (otherwise they
+ // would affect codegen).
+ Instruction *Inst = --ScanFrom;
+ if (isa<DbgInfoIntrinsic>(Inst))
+ continue;
+ // Restore ScanFrom to expected value in case next test succeeds
+ ScanFrom++;
+
// Don't scan huge blocks.
if (MaxInstsToScan-- == 0) return 0;
- Instruction *Inst = --ScanFrom;
-
+ --ScanFrom;
// If this is a load of Ptr, the loaded value is available.
if (LoadInst *LI = dyn_cast<LoadInst>(Inst))
if (AreEquivalentAddressValues(LI->getOperand(0), Ptr))
@@ -523,3 +531,18 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
// block.
return 0;
}
+
+/// CopyPrecedingStopPoint - If I is immediately preceded by a StopPoint,
+/// make a copy of the stoppoint before InsertPos (presumably before copying
+/// or moving I).
+void llvm::CopyPrecedingStopPoint(Instruction *I,
+ BasicBlock::iterator InsertPos) {
+ if (I != I->getParent()->begin()) {
+ BasicBlock::iterator BBI = I; --BBI;
+ if (DbgStopPointInst *DSPI = dyn_cast<DbgStopPointInst>(BBI)) {
+ DbgStopPointInst *newDSPI =
+ reinterpret_cast<DbgStopPointInst*>(DSPI->clone());
+ newDSPI->insertBefore(InsertPos);
+ }
+ }
+}