diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 97af83f4e5..b4262743a3 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -11007,8 +11007,14 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI, } } - const Type *DestPTy = cast<PointerType>(CI->getType())->getElementType(); + const PointerType *DestTy = cast<PointerType>(CI->getType()); + const Type *DestPTy = DestTy->getElementType(); if (const PointerType *SrcTy = dyn_cast<PointerType>(CastOp->getType())) { + + // If the address spaces don't match, don't eliminate the cast. + if (DestTy->getAddressSpace() != SrcTy->getAddressSpace()) + return 0; + const Type *SrcPTy = SrcTy->getElementType(); if (DestPTy->isInteger() || isa<PointerType>(DestPTy) || |