aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorWojciech Matyjewicz <wmatyjewicz@fastmail.fm>2008-02-09 18:30:13 +0000
committerWojciech Matyjewicz <wmatyjewicz@fastmail.fm>2008-02-09 18:30:13 +0000
commit3913187bf6135e6a71260c65eed664095c8f9ce9 (patch)
tree448300944275533d26213e3b53d99b38524f977a /lib/Analysis
parent402689d11a3879163a3e67ea297937c2c26cc502 (diff)
downloadexternal_llvm-3913187bf6135e6a71260c65eed664095c8f9ce9.zip
external_llvm-3913187bf6135e6a71260c65eed664095c8f9ce9.tar.gz
external_llvm-3913187bf6135e6a71260c65eed664095c8f9ce9.tar.bz2
We should check that existing cast operation has the appropriate opcode before we reuse it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46908 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index f3e508a..3e05600 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -30,36 +30,38 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
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))