Fix isEliminableCastPair to work correctly in the presence of pointers

with different sizes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167018 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands
2012-10-30 16:03:32 +00:00
parent 92b469971e
commit 446cf94cdb
5 changed files with 61 additions and 13 deletions
@@ -238,16 +238,20 @@ isEliminableCastPair(
// Get the opcodes of the two Cast instructions
Instruction::CastOps firstOp = Instruction::CastOps(CI->getOpcode());
Instruction::CastOps secondOp = Instruction::CastOps(opcode);
Type *SrcIntPtrTy = TD && SrcTy->isPtrOrPtrVectorTy() ?
TD->getIntPtrType(SrcTy) : 0;
Type *MidIntPtrTy = TD && MidTy->isPtrOrPtrVectorTy() ?
TD->getIntPtrType(MidTy) : 0;
Type *DstIntPtrTy = TD && DstTy->isPtrOrPtrVectorTy() ?
TD->getIntPtrType(DstTy) : 0;
unsigned Res = CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy,
DstTy,
TD ? TD->getIntPtrType(DstTy) : 0);
DstTy, SrcIntPtrTy, MidIntPtrTy,
DstIntPtrTy);
// We don't want to form an inttoptr or ptrtoint that converts to an integer
// type that differs from the pointer size.
if ((Res == Instruction::IntToPtr &&
(!TD || SrcTy != TD->getIntPtrType(DstTy))) ||
(Res == Instruction::PtrToInt &&
(!TD || DstTy != TD->getIntPtrType(SrcTy))))
if ((Res == Instruction::IntToPtr && SrcTy != DstIntPtrTy) ||
(Res == Instruction::PtrToInt && DstTy != SrcIntPtrTy))
Res = 0;
return Instruction::CastOps(Res);