summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2010-02-13 23:38:01 +0000
committerEric Christopher <echristo@apple.com>2010-02-13 23:38:01 +0000
commit843a4cc43c6b4205d3806859e0d1df2c8a9a2afe (patch)
treee2e7333d6e0700836d05f5cbae688c118bae043b /llvm/lib/Transforms
parentcce9ee8970c0f684e5ada45efe222331875e8aca (diff)
downloadbcm5719-llvm-843a4cc43c6b4205d3806859e0d1df2c8a9a2afe.tar.gz
bcm5719-llvm-843a4cc43c6b4205d3806859e0d1df2c8a9a2afe.zip
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. llvm-svn: 96134
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 43419eb9fc0..e501ddc4b85 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/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);
OpenPOWER on IntegriCloud