diff options
author | David Blaikie <dblaikie@gmail.com> | 2015-05-06 23:56:21 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2015-05-06 23:56:21 +0000 |
commit | 567d0e5a90ffbc579136af2dfcee81c2310bdc47 (patch) | |
tree | 3199c66c8b493f8adfc79e82fb48fbc375f885e9 /llvm/lib/IR/ConstantFold.cpp | |
parent | 3058d0f08026583f1db33a040eac0f8f654dff41 (diff) | |
download | llvm-567d0e5a90ffbc579136af2dfcee81c2310bdc47.zip llvm-567d0e5a90ffbc579136af2dfcee81c2310bdc47.tar.gz llvm-567d0e5a90ffbc579136af2dfcee81c2310bdc47.tar.bz2 |
Revert "[opaque pointer type] Pass explicit pointer type through GEP constant folding"
Causes regressions in Clang. Reverting while I investigate.
This reverts commit r236670.
llvm-svn: 236678
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 8afb3e4..2a52493 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -2028,7 +2028,7 @@ static bool isIndexInRangeOfSequentialType(const SequentialType *STy, } template<typename IndexTy> -static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, +static Constant *ConstantFoldGetElementPtrImpl(Constant *C, bool inBounds, ArrayRef<IndexTy> Idxs) { if (Idxs.empty()) return C; @@ -2165,9 +2165,9 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, // factored out into preceding dimensions. bool Unknown = false; SmallVector<Constant *, 8> NewIdxs; - Type *Ty = PointeeTy; - Type *Prev = C->getType(); - for (unsigned i = 1, e = Idxs.size(); i != e; + Type *Ty = C->getType(); + Type *Prev = nullptr; + for (unsigned i = 0, 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)) @@ -2229,7 +2229,7 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, if (!Unknown && !inBounds) if (auto *GV = dyn_cast<GlobalVariable>(C)) if (!GV->hasExternalWeakLinkage() && isInBoundsIndices(Idxs)) - return ConstantExpr::getInBoundsGetElementPtr(PointeeTy, C, Idxs); + return ConstantExpr::getInBoundsGetElementPtr(nullptr, C, Idxs); return nullptr; } @@ -2237,27 +2237,11 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, Constant *llvm::ConstantFoldGetElementPtr(Constant *C, bool inBounds, ArrayRef<Constant *> Idxs) { - return ConstantFoldGetElementPtrImpl( - cast<PointerType>(C->getType()->getScalarType())->getElementType(), C, - inBounds, Idxs); + return ConstantFoldGetElementPtrImpl(C, inBounds, Idxs); } Constant *llvm::ConstantFoldGetElementPtr(Constant *C, bool inBounds, ArrayRef<Value *> Idxs) { - return ConstantFoldGetElementPtrImpl( - cast<PointerType>(C->getType()->getScalarType())->getElementType(), C, - inBounds, Idxs); -} - -Constant *llvm::ConstantFoldGetElementPtr(Type *Ty, Constant *C, - bool inBounds, - ArrayRef<Constant *> Idxs) { - return ConstantFoldGetElementPtrImpl(Ty, C, inBounds, Idxs); -} - -Constant *llvm::ConstantFoldGetElementPtr(Type *Ty, Constant *C, - bool inBounds, - ArrayRef<Value *> Idxs) { - return ConstantFoldGetElementPtrImpl(Ty, C, inBounds, Idxs); + return ConstantFoldGetElementPtrImpl(C, inBounds, Idxs); } |