diff options
| author | Dan Gohman <gohman@apple.com> | 2009-04-16 15:52:57 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-04-16 15:52:57 +0000 |
| commit | 66e038a3e3e347d039383f24955bb1ce5217f110 (patch) | |
| tree | 6cbdcbe3eef02d374f0eb31dec903070c4548d81 | |
| parent | 8798bd1bf9fbfe7bd1ad2e1a93351b3e2f7a9c19 (diff) | |
| download | bcm5719-llvm-66e038a3e3e347d039383f24955bb1ce5217f110.tar.gz bcm5719-llvm-66e038a3e3e347d039383f24955bb1ce5217f110.zip | |
Teach SCEVExpander::InsertCastOfTo to avoid creating inttoptr-of-ptrtoint
and ptrtoint-of-inttoptr expressions. This fixes a regression in 300.twolf.
llvm-svn: 69293
| -rw-r--r-- | llvm/include/llvm/Analysis/ScalarEvolutionExpander.h | 4 | ||||
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h index 8126a589a45..2f660c9c5b3 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h @@ -83,8 +83,8 @@ namespace llvm { /// InsertCastOfTo - Insert a cast of V to the specified type, doing what /// we can to share the casts. - static Value *InsertCastOfTo(Instruction::CastOps opcode, Value *V, - const Type *Ty); + Value *InsertCastOfTo(Instruction::CastOps opcode, Value *V, + const Type *Ty); /// InsertBinop - Insert the specified binary operator, doing a small amount /// of work to avoid inserting an obviously redundant operation. static Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index d91061b2b3a..0033fb4ae4a 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -26,6 +26,14 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V, if (opcode == Instruction::BitCast && V->getType() == Ty) return V; + // Short-circuit unnecessary inttoptr<->ptrtoint casts. + if (opcode == Instruction::PtrToInt && Ty == TD.getIntPtrType()) + if (IntToPtrInst *ITP = dyn_cast<IntToPtrInst>(V)) + return ITP->getOperand(0); + if (opcode == Instruction::IntToPtr && V->getType() == TD.getIntPtrType()) + if (PtrToIntInst *PTI = dyn_cast<PtrToIntInst>(V)) + return PTI->getOperand(0); + // FIXME: keep track of the cast instruction. if (Constant *C = dyn_cast<Constant>(V)) return ConstantExpr::getCast(opcode, C, Ty); |

