X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FConstantFold.cpp;h=131c5c51790414c6b1c81e27aaa3a1710c22d042;hb=996ace13c0eca0ce1c21df9d7b84966416dd1c21;hp=8afb3e489de266927bfbc355eb817dc6787574e6;hpb=cb0a50fe54167b6e9d55d1f83629800078f2b2e4;p=oota-llvm.git diff --git a/lib/IR/ConstantFold.cpp b/lib/IR/ConstantFold.cpp index 8afb3e489de..131c5c51790 100644 --- a/lib/IR/ConstantFold.cpp +++ b/lib/IR/ConstantFold.cpp @@ -632,8 +632,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V, if (ConstantExpr *CE = dyn_cast(V)) if (CE->getOpcode() == Instruction::GetElementPtr && CE->getOperand(0)->isNullValue()) { - Type *Ty = - cast(CE->getOperand(0)->getType())->getElementType(); + GEPOperator *GEPO = cast(CE); + Type *Ty = GEPO->getSourceElementType(); if (CE->getNumOperands() == 2) { // Handle a sizeof-like expression. Constant *Idx = CE->getOperand(1); @@ -1385,7 +1385,7 @@ static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1, if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage()) return true; if (const auto *GVar = dyn_cast(GV)) { - Type *Ty = GVar->getType()->getPointerElementType(); + Type *Ty = GVar->getValueType(); // A global with opaque type might end up being zero sized. if (!Ty->isSized()) return true; @@ -1997,17 +1997,16 @@ static bool isInBoundsIndices(ArrayRef Idxs) { } /// \brief Test whether a given ConstantInt is in-range for a SequentialType. -static bool isIndexInRangeOfSequentialType(const SequentialType *STy, +static bool isIndexInRangeOfSequentialType(SequentialType *STy, const ConstantInt *CI) { - if (const PointerType *PTy = dyn_cast(STy)) - // Only handle pointers to sized types, not pointers to functions. - return PTy->getElementType()->isSized(); + if (isa(STy)) + return true; uint64_t NumElements = 0; // Determine the number of elements in our sequential type. - if (const ArrayType *ATy = dyn_cast(STy)) + if (auto *ATy = dyn_cast(STy)) NumElements = ATy->getNumElements(); - else if (const VectorType *VTy = dyn_cast(STy)) + else if (auto *VTy = dyn_cast(STy)) NumElements = VTy->getNumElements(); assert((isa(STy) || NumElements > 0) && @@ -2163,10 +2162,10 @@ 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 NewIdxs; Type *Ty = PointeeTy; Type *Prev = C->getType(); + bool Unknown = !isa(Idxs[0]); for (unsigned i = 1, e = Idxs.size(); i != e; Prev = Ty, Ty = cast(Ty)->getTypeAtIndex(Idxs[i]), ++i) { if (ConstantInt *CI = dyn_cast(Idxs[i])) { @@ -2178,7 +2177,7 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, // dimension. NewIdxs.resize(Idxs.size()); uint64_t NumElements = 0; - if (const ArrayType *ATy = dyn_cast(Ty)) + if (auto *ATy = dyn_cast(Ty)) NumElements = ATy->getNumElements(); else NumElements = cast(Ty)->getNumElements(); @@ -2221,7 +2220,7 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, if (!NewIdxs.empty()) { for (unsigned i = 0, e = Idxs.size(); i != e; ++i) if (!NewIdxs[i]) NewIdxs[i] = cast(Idxs[i]); - return ConstantExpr::getGetElementPtr(nullptr, C, NewIdxs, inBounds); + return ConstantExpr::getGetElementPtr(PointeeTy, C, NewIdxs, inBounds); } // If all indices are known integers and normalized, we can do a simple