X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FConstantFold.cpp;h=68ddf096754733cd6d308cc1807471c086731609;hb=f1c277c27096a55a1ab2220294a69457d0951bf7;hp=2efc61242eac655f78c8ffa43b65e10359fa5c0b;hpb=bcca6160292c1446bfcd6c8d222217329ae6de8b;p=oota-llvm.git diff --git a/lib/IR/ConstantFold.cpp b/lib/IR/ConstantFold.cpp index 2efc61242ea..68ddf096754 100644 --- a/lib/IR/ConstantFold.cpp +++ b/lib/IR/ConstantFold.cpp @@ -83,7 +83,7 @@ foldConstantCastPair( assert(DstTy && DstTy->isFirstClassType() && "Invalid cast destination type"); assert(CastInst::isCast(opc) && "Invalid cast opcode"); - // The the types and opcodes for the two Cast constant expressions + // The types and opcodes for the two Cast constant expressions Type *SrcTy = Op->getOperand(0)->getType(); Type *MidTy = Op->getType(); Instruction::CastOps firstOp = Instruction::CastOps(Op->getOpcode()); @@ -1187,7 +1187,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, (void)C3V.divide(C2V, APFloat::rmNearestTiesToEven); return ConstantFP::get(C1->getContext(), C3V); case Instruction::FRem: - (void)C3V.mod(C2V, APFloat::rmNearestTiesToEven); + (void)C3V.mod(C2V); return ConstantFP::get(C1->getContext(), C3V); } } @@ -1277,9 +1277,9 @@ static bool isMaybeZeroSizedType(Type *Ty) { } /// IdxCompare - Compare the two constants as though they were getelementptr -/// indices. This allows coersion of the types to be the same thing. +/// indices. This allows coercion of the types to be the same thing. /// -/// If the two constants are the "same" (after coersion), return 0. If the +/// If the two constants are the "same" (after coercion), return 0. If the /// first is less than the second, return -1, if the second is less than the /// first, return 1. If the constants are not integral, return -2. /// @@ -1997,17 +1997,17 @@ 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(); + // And indices are valid when indexing along a pointer + 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,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 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(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])) { if (isa(Ty) || isa(Ty)) @@ -2178,7 +2178,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();