summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-05-05 22:41:33 +0000
committerChris Lattner <sabre@nondot.org>2007-05-05 22:41:33 +0000
commit8c756c1fff2b203cbc8173a44c312ee2fad8758d (patch)
tree5a4933de82b3a7e179eaf8b060a0f4a38856007e /lib/Transforms
parenta993dd0cfc7a8693e727c2532438443309987c3d (diff)
downloadllvm-8c756c1fff2b203cbc8173a44c312ee2fad8758d.tar.gz
llvm-8c756c1fff2b203cbc8173a44c312ee2fad8758d.tar.bz2
llvm-8c756c1fff2b203cbc8173a44c312ee2fad8758d.tar.xz
Implement Transforms/InstCombine/cast_ptr.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36809 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index efeb8344b9..672fe852e6 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -5593,7 +5593,28 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
const Type *DestTy = LHSCI->getType();
Value *RHSCIOp;
- // We only handle extension cast instructions, so far. Enforce this.
+ // Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the
+ // integer type is the same size as the pointer type.
+ if (LHSCI->getOpcode() == Instruction::PtrToInt &&
+ getTargetData().getPointerSizeInBits() ==
+ cast<IntegerType>(DestTy)->getBitWidth()) {
+ Value *RHSOp = 0;
+ if (Constant *RHSC = dyn_cast<Constant>(ICI.getOperand(1))) {
+ RHSOp = ConstantExpr::getPtrToInt(RHSC, SrcTy);
+ } else if (PtrToIntInst *RHSC = dyn_cast<PtrToIntInst>(ICI.getOperand(1))) {
+ RHSOp = RHSC->getOperand(0);
+ // If the pointer types don't match, insert a bitcast.
+ if (LHSCIOp->getType() != RHSOp->getType())
+ RHSOp = InsertCastBefore(Instruction::BitCast, RHSOp,
+ LHSCIOp->getType(), ICI);
+ }
+
+ if (RHSOp)
+ return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSOp);
+ }
+
+ // The code below only handles extension cast instructions, so far.
+ // Enforce this.
if (LHSCI->getOpcode() != Instruction::ZExt &&
LHSCI->getOpcode() != Instruction::SExt)
return 0;