aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-06 17:11:01 +0000
committerChris Lattner <sabre@nondot.org>2003-10-06 17:11:01 +0000
commit4bb7c02eba2e83288d0ab4bc9d3febbfcb131804 (patch)
treeddc43835abfcddf06fbeb7e2ac609b29126ec528 /lib
parent884d6c4e10501116a8ff45616231564a2738dadd (diff)
downloadexternal_llvm-4bb7c02eba2e83288d0ab4bc9d3febbfcb131804.zip
external_llvm-4bb7c02eba2e83288d0ab4bc9d3febbfcb131804.tar.gz
external_llvm-4bb7c02eba2e83288d0ab4bc9d3febbfcb131804.tar.bz2
Minor speedups for the instcombine pass
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8894 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 465954a..b2b63af 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1939,17 +1939,16 @@ bool InstCombiner::runOnFunction(Function &F) {
// Check to see if we can DIE the instruction...
if (isInstructionTriviallyDead(I)) {
// Add operands to the worklist...
- for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
- if (Instruction *Op = dyn_cast<Instruction>(I->getOperand(i)))
- WorkList.push_back(Op);
-
+ if (I->getNumOperands() < 4)
+ for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
+ if (Instruction *Op = dyn_cast<Instruction>(I->getOperand(i)))
+ WorkList.push_back(Op);
++NumDeadInst;
- BasicBlock::iterator BBI = I;
- if (dceInstruction(BBI)) {
- removeFromWorkList(I);
- continue;
- }
- }
+
+ I->getParent()->getInstList().erase(I);
+ removeFromWorkList(I);
+ continue;
+ }
// Instruction isn't dead, see if we can constant propagate it...
if (Constant *C = ConstantFoldInstruction(I)) {
@@ -1960,13 +1959,10 @@ bool InstCombiner::runOnFunction(Function &F) {
ReplaceInstUsesWith(*I, C);
++NumConstProp;
- BasicBlock::iterator BBI = I;
- if (dceInstruction(BBI)) {
- removeFromWorkList(I);
- continue;
- }
+ I->getParent()->getInstList().erase(I);
+ continue;
}
-
+
// Now that we have an instruction, try combining it to simplify it...
if (Instruction *Result = visit(*I)) {
++NumCombined;
@@ -1975,7 +1971,20 @@ bool InstCombiner::runOnFunction(Function &F) {
// Instructions can end up on the worklist more than once. Make sure
// we do not process an instruction that has been deleted.
removeFromWorkList(I);
- ReplaceInstWithInst(I, Result);
+
+ // Move the name to the new instruction first...
+ std::string OldName = I->getName(); I->setName("");
+ Result->setName(I->getName());
+
+ // Insert the new instruction into the basic block...
+ BasicBlock *InstParent = I->getParent();
+ InstParent->getInstList().insert(I, Result);
+
+ // Everything uses the new instruction now...
+ I->replaceAllUsesWith(Result);
+
+ // Erase the old instruction.
+ InstParent->getInstList().erase(I);
} else {
BasicBlock::iterator II = I;