diff options
author | Eric Christopher <echristo@apple.com> | 2010-02-13 23:38:01 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2010-02-13 23:38:01 +0000 |
commit | 77ffe3b31e32fbbcb06e71c8a68129df6266a492 (patch) | |
tree | bf6f2d2f17063adf9d10b578348cba9aafe3edba /lib/Transforms | |
parent | 18c67b994c1f437aa1b61d60f9eecf62f2762952 (diff) |
Fix a problem where we had bitcasted operands that gave us
odd offsets since the bitcasted pointer size and the offset pointer
size are going to be different types for the GEP vs base object.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96134 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCalls.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index 43419eb9fc..e501ddc4b8 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -334,17 +334,21 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { // Make sure we're not a constant offset from an external // global. Value *Operand = GEP->getPointerOperand(); + Operand = Operand->stripPointerCasts(); if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand)) if (!GV->hasDefinitiveInitializer()) break; - // Get what we're pointing to and its size. - const PointerType *PT = + // Get what we're pointing to and its size. + const PointerType *BaseType = cast<PointerType>(Operand->getType()); - size_t Size = TD->getTypeAllocSize(PT->getElementType()); + size_t Size = TD->getTypeAllocSize(BaseType->getElementType()); - // Get the current byte offset into the thing. + // Get the current byte offset into the thing. Use the original + // operand in case we're looking through a bitcast. SmallVector<Value*, 8> Ops(CE->op_begin()+1, CE->op_end()); - size_t Offset = TD->getIndexedOffset(PT, &Ops[0], Ops.size()); + const PointerType *OffsetType = + cast<PointerType>(GEP->getPointerOperand()->getType()); + size_t Offset = TD->getIndexedOffset(OffsetType, &Ops[0], Ops.size()); assert(Size >= Offset); |