diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-04-14 22:01:22 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-04-14 22:01:22 +0000 |
| commit | d420fe63ea195c7d64096d604018cc42fede0fd9 (patch) | |
| tree | d0033f5be81027380c5bbc5a127df02d339cd7a4 /llvm/lib/Analysis | |
| parent | e3e2c91997708ebd24345ab31f4e9b111dacd5d5 (diff) | |
| download | bcm5719-llvm-d420fe63ea195c7d64096d604018cc42fede0fd9.tar.gz bcm5719-llvm-d420fe63ea195c7d64096d604018cc42fede0fd9.zip | |
Implement a FIXME: if we're going to insert a cast, we might as well only
insert it once!
llvm-svn: 12955
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 62247e42ac4..f96cd5d82b8 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2484,7 +2484,21 @@ Value *ScalarEvolutionRewriter::ExpandCodeFor(SCEVHandle SH, if (Constant *C = dyn_cast<Constant>(V)) return ConstantExpr::getCast(C, Ty); else if (Instruction *I = dyn_cast<Instruction>(V)) { - // FIXME: check to see if there is already a cast! + // 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 (It != BasicBlock::iterator(CI)) { + // Splice the cast immediately after the operand in question. + I->getParent()->getInstList().splice(It, + CI->getParent()->getInstList(), + CI); + } + return CI; + } + } BasicBlock::iterator IP = I; ++IP; if (InvokeInst *II = dyn_cast<InvokeInst>(I)) IP = II->getNormalDest()->begin(); |

