diff options
author | Owen Anderson <resistor@mac.com> | 2010-08-30 23:34:17 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2010-08-30 23:34:17 +0000 |
commit | a081d15b842e87c670260006eb17b5c1a826b5ee (patch) | |
tree | fb3f4cf7cc61865804ab076a581ea781b87a8824 | |
parent | 327ca7bec274e25c05a0a4ae5b51a8a2062012c7 (diff) |
Cleanups suggested by Chris.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112553 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/ValuePropagation.cpp | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/lib/Transforms/Scalar/ValuePropagation.cpp b/lib/Transforms/Scalar/ValuePropagation.cpp index 7e4fb8b3ce..b4b07640e4 100644 --- a/lib/Transforms/Scalar/ValuePropagation.cpp +++ b/lib/Transforms/Scalar/ValuePropagation.cpp @@ -53,67 +53,65 @@ Pass *llvm::createValuePropagationPass() { } bool ValuePropagation::processSelect(SelectInst *S) { + if (S->getType()->isVectorTy()) return false; + Constant *C = LVI->getConstant(S->getOperand(0), S->getParent()); if (!C) return false; ConstantInt *CI = dyn_cast<ConstantInt>(C); if (!CI) return false; - if (CI->isZero()) { - S->replaceAllUsesWith(S->getOperand(2)); - S->eraseFromParent(); - } else if (CI->isOne()) { - S->replaceAllUsesWith(S->getOperand(1)); - S->eraseFromParent(); - } else { - assert(0 && "Select on constant is neither 0 nor 1?"); - } - + S->replaceAllUsesWith(S->getOperand(CI->isOne() ? 1 : 2)); + S->eraseFromParent(); + ++NumSelects; return true; } bool ValuePropagation::processPHI(PHINode *P) { - bool changed = false; + bool Changed = false; BasicBlock *BB = P->getParent(); - for (unsigned i = 0; i < P->getNumIncomingValues(); ++i) { + for (unsigned i = 0, e = P->getNumIncomingValues(); i < e; ++i) { + Value *Incoming = P->getIncomingValue(i); + if (isa<Constant>(Incoming)) continue; + Constant *C = LVI->getConstantOnEdge(P->getIncomingValue(i), P->getIncomingBlock(i), BB); - if (!C || C == P->getIncomingValue(i)) continue; + if (!C) continue; P->setIncomingValue(i, C); - changed = true; + Changed = true; } if (Value *ConstVal = P->hasConstantValue()) { P->replaceAllUsesWith(ConstVal); P->eraseFromParent(); - changed = true; + Changed = true; } ++NumPhis; - return changed; + return Changed; } bool ValuePropagation::runOnFunction(Function &F) { LVI = &getAnalysis<LazyValueInfo>(); - bool changed = false; + bool Changed = false; for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ) { Instruction *II = BI++; if (SelectInst *SI = dyn_cast<SelectInst>(II)) - changed |= processSelect(SI); + Changed |= processSelect(SI); else if (PHINode *P = dyn_cast<PHINode>(II)) - changed |= processPHI(P); + Changed |= processPHI(P); } - if (changed) + if (Changed) for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) SimplifyInstructionsInBlock(FI); |