[llvm-commits] [llvm] r46908 - /llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
Wojciech Matyjewicz
wmatyjewicz at fastmail.fm
Sat Feb 9 10:30:13 PST 2008
Author: wmat
Date: Sat Feb 9 12:30:13 2008
New Revision: 46908
URL: http://llvm.org/viewvc/llvm-project?rev=46908&view=rev
Log:
We should check that existing cast operation has the appropriate opcode before we reuse it.
Modified:
llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=46908&r1=46907&r2=46908&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Sat Feb 9 12:30:13 2008
@@ -30,36 +30,38 @@
for (Value::use_iterator UI = A->use_begin(), E = A->use_end();
UI != E; ++UI) {
if ((*UI)->getType() == Ty)
- if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI))) {
- // If the cast isn't the first instruction of the function, move it.
- if (BasicBlock::iterator(CI) !=
- A->getParent()->getEntryBlock().begin()) {
- CI->moveBefore(A->getParent()->getEntryBlock().begin());
+ if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI)))
+ if (CI->getOpcode() == opcode) {
+ // If the cast isn't the first instruction of the function, move it.
+ if (BasicBlock::iterator(CI) !=
+ A->getParent()->getEntryBlock().begin()) {
+ CI->moveBefore(A->getParent()->getEntryBlock().begin());
+ }
+ return CI;
}
- return CI;
- }
}
return CastInst::create(opcode, V, Ty, V->getName(),
A->getParent()->getEntryBlock().begin());
}
-
+
Instruction *I = cast<Instruction>(V);
-
+
// Check to see if there is already a cast. If there is, use it.
for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
UI != E; ++UI) {
if ((*UI)->getType() == Ty)
- if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI))) {
- BasicBlock::iterator It = I; ++It;
- if (isa<InvokeInst>(I))
- It = cast<InvokeInst>(I)->getNormalDest()->begin();
- while (isa<PHINode>(It)) ++It;
- if (It != BasicBlock::iterator(CI)) {
- // Splice the cast immediately after the operand in question.
- CI->moveBefore(It);
+ if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI)))
+ if (CI->getOpcode() == opcode) {
+ BasicBlock::iterator It = I; ++It;
+ if (isa<InvokeInst>(I))
+ It = cast<InvokeInst>(I)->getNormalDest()->begin();
+ while (isa<PHINode>(It)) ++It;
+ if (It != BasicBlock::iterator(CI)) {
+ // Splice the cast immediately after the operand in question.
+ CI->moveBefore(It);
+ }
+ return CI;
}
- return CI;
- }
}
BasicBlock::iterator IP = I; ++IP;
if (InvokeInst *II = dyn_cast<InvokeInst>(I))
More information about the llvm-commits
mailing list