aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-05-01 17:00:00 +0000
committerDan Gohman <gohman@apple.com>2009-05-01 17:00:00 +0000
commit80dcdee0f48820ecea86c15768324945bb0d68d1 (patch)
tree1b336d4f6c4d444dc89c32d6207caf0fbdc2c3b3 /lib/Analysis/ScalarEvolutionExpander.cpp
parent99a1302ae4c438ab532826685280c0b69687e163 (diff)
Short-circuit inttoptr-ptrtoint constant expressions; these aren't
always folded by the regular constant folder because it doesn't have TargetData information. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70553 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index 9676ea20af..be91c0d724 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -27,13 +27,20 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
// Short-circuit unnecessary inttoptr<->ptrtoint casts.
if ((opcode == Instruction::PtrToInt || opcode == Instruction::IntToPtr) &&
- SE.getTypeSizeInBits(Ty) == SE.getTypeSizeInBits(V->getType()))
+ SE.getTypeSizeInBits(Ty) == SE.getTypeSizeInBits(V->getType())) {
if (CastInst *CI = dyn_cast<CastInst>(V))
if ((CI->getOpcode() == Instruction::PtrToInt ||
CI->getOpcode() == Instruction::IntToPtr) &&
SE.getTypeSizeInBits(CI->getType()) ==
SE.getTypeSizeInBits(CI->getOperand(0)->getType()))
return CI->getOperand(0);
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
+ if ((CE->getOpcode() == Instruction::PtrToInt ||
+ CE->getOpcode() == Instruction::IntToPtr) &&
+ SE.getTypeSizeInBits(CE->getType()) ==
+ SE.getTypeSizeInBits(CE->getOperand(0)->getType()))
+ return CE->getOperand(0);
+ }
// FIXME: keep track of the cast instruction.
if (Constant *C = dyn_cast<Constant>(V))