summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2015-06-12 18:22:03 +0000
committerDavid Blaikie <dblaikie@gmail.com>2015-06-12 18:22:03 +0000
commit473b943ea86263e30bef815daa16e50025557ac9 (patch)
tree34432c5c8883ef7f617b294b623919f20796043e /llvm/lib
parenta4afccd8a898d3ba0c4894e1a7d98d4457deded5 (diff)
downloadbcm5719-llvm-473b943ea86263e30bef815daa16e50025557ac9.tar.gz
bcm5719-llvm-473b943ea86263e30bef815daa16e50025557ac9.zip
Refix a use of explicit pointer types in GEP constant folding
In the glorious future of opaque pointer types, it won't be possible to retrieve the pointee type of a pointer type which is what's being done in this GEP loop - but the first iteration is always a pointer type and the loop doesn't care about that case, except whether or not the index is a constant. So pull that special case out before the loop and start at the second iteration (index 1) instead. Originally committed in r236670 and reverted with a test case in r239015. This change keeps the test case working while also avoiding depending on pointee types. llvm-svn: 239629
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 2efc61242ea..46bb20e0d1b 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -2163,11 +2163,11 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C,
// Check to see if any array indices are not within the corresponding
// notional array or vector bounds. If so, try to determine if they can be
// factored out into preceding dimensions.
- bool Unknown = false;
SmallVector<Constant *, 8> NewIdxs;
- Type *Ty = C->getType();
- Type *Prev = nullptr;
- for (unsigned i = 0, e = Idxs.size(); i != e;
+ Type *Ty = PointeeTy;
+ Type *Prev = C->getType();
+ bool Unknown = !isa<ConstantInt>(Idxs[0]);
+ for (unsigned i = 1, e = Idxs.size(); i != e;
Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
if (isa<ArrayType>(Ty) || isa<VectorType>(Ty))
OpenPOWER on IntegriCloud