diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2008-05-17 09:03:26 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2008-05-17 09:03:26 +0000 |
commit | d24ae8703f2da048b351d6c9c83d1412439e737c (patch) | |
tree | 3516a81c3f26952b520be2210e95926b1494ca84 /lib/VMCore/ConstantFold.cpp | |
parent | fc1efbbfbcd707c29bdab8a1adf7b649f42e9600 (diff) | |
download | external_llvm-d24ae8703f2da048b351d6c9c83d1412439e737c.zip external_llvm-d24ae8703f2da048b351d6c9c83d1412439e737c.tar.gz external_llvm-d24ae8703f2da048b351d6c9c83d1412439e737c.tar.bz2 |
Constant fold inttoptr and ptrtoint.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51216 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 0913c48..e381f3b 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -1029,6 +1029,29 @@ static ICmpInst::Predicate evaluateICmpRelation(const Constant *V1, } break; + case Instruction::PtrToInt: + case Instruction::IntToPtr: + // inttoptr(x1) != inttoptr(x2) iff x1 != x2 + if (const ConstantExpr *CE2 = dyn_cast<ConstantExpr>(V2)) + if (CE1->getOpcode() == CE2->getOpcode()) { + Constant *Op1 = const_cast<Constant*>(CE1Op0); + Constant *Op2 = CE2->getOperand(0); + if (CE1Op->getType() == CE2Op->getType()) { + ConstantInt *R = 0; + + ICmpInst::Predicate pred = ICmpInst::ICMP_EQ; + R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, Op1, Op2)); + if (R && !R->isZero()) + return pred; + + pred = ICmpInst::ICMP_NE; + R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, Op1, Op2)); + if (R && !R->isZero()) + return pred; + } + } + break; + case Instruction::GetElementPtr: // Ok, since this is a getelementptr, we know that the constant has a // pointer type. Check the various cases. |