diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 85 | ||||
-rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/VMCore/Value.cpp | 2 |
6 files changed, 9 insertions, 117 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index dcb5903a14e..308c69a87ee 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -38,13 +38,8 @@ using namespace llvm; // Useful predicates //===----------------------------------------------------------------------===// -static const User *isGEP(const Value *V) { - if (const GEPOperator *GEP = dyn_cast<GEPOperator>(V)) - // For the purposes of BasicAliasAnalysis, if the GEP has overflow it - // could do crazy things. - if (GEP->hasNoPointerOverflow()) - return GEP; - return 0; +static const GEPOperator *isGEP(const Value *V) { + return dyn_cast<GEPOperator>(V); } static const Value *GetGEPOperands(const Value *V, diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 6c23f401c5b..aadba9d9d3d 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2938,15 +2938,10 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) { return getSCEV(U->getOperand(0)); break; - case Instruction::IntToPtr: - if (!TD) break; // Without TD we can't analyze pointers. - return getTruncateOrZeroExtend(getSCEV(U->getOperand(0)), - TD->getIntPtrType()); - - case Instruction::PtrToInt: - if (!TD) break; // Without TD we can't analyze pointers. - return getTruncateOrZeroExtend(getSCEV(U->getOperand(0)), - U->getType()); + // It's tempting to handle inttoptr and ptrtoint, however this can + // lead to pointer expressions which cannot be expanded to GEPs + // (because they may overflow). For now, the only pointer-typed + // expressions we handle are GEPs and address literals. case Instruction::GetElementPtr: if (!TD) break; // Without TD we can't analyze pointers. diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 94547b48bb5..d2ed1e14e3f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2276,31 +2276,6 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { return R; } - // add (cast *A to intptrtype) B -> - // cast (GEP (cast *A to i8*) B) --> intptrtype - { - CastInst *CI = dyn_cast<CastInst>(LHS); - Value *Other = RHS; - if (!CI) { - CI = dyn_cast<CastInst>(RHS); - Other = LHS; - } - if (CI && CI->getType()->isSized() && - (CI->getType()->getScalarSizeInBits() == - TD->getIntPtrType()->getPrimitiveSizeInBits()) - && isa<PointerType>(CI->getOperand(0)->getType())) { - unsigned AS = - cast<PointerType>(CI->getOperand(0)->getType())->getAddressSpace(); - Value *I2 = InsertBitCastBefore(CI->getOperand(0), - Context->getPointerType(Type::Int8Ty, AS), I); - GetElementPtrInst *GEP = GetElementPtrInst::Create(I2, Other, "ctg2"); - // A GEP formed from an arbitrary add may overflow. - cast<GEPOperator>(GEP)->setHasNoPointerOverflow(false); - I2 = InsertNewInstBefore(GEP, I); - return new PtrToIntInst(I2, CI->getType()); - } - } - // add (select X 0 (sub n A)) A --> select X A n { SelectInst *SI = dyn_cast<SelectInst>(LHS); @@ -8914,65 +8889,7 @@ Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) { if (Instruction *I = commonCastTransforms(CI)) return I; - - const Type *DestPointee = cast<PointerType>(CI.getType())->getElementType(); - if (!DestPointee->isSized()) return 0; - - // If this is inttoptr(add (ptrtoint x), cst), try to turn this into a GEP. - ConstantInt *Cst; - Value *X; - if (match(CI.getOperand(0), m_Add(m_Cast<PtrToIntInst>(m_Value(X)), - m_ConstantInt(Cst)), *Context)) { - // If the source and destination operands have the same type, see if this - // is a single-index GEP. - if (X->getType() == CI.getType()) { - // Get the size of the pointee type. - uint64_t Size = TD->getTypeAllocSize(DestPointee); - - // Convert the constant to intptr type. - APInt Offset = Cst->getValue(); - Offset.sextOrTrunc(TD->getPointerSizeInBits()); - - // If Offset is evenly divisible by Size, we can do this xform. - if (Size && !APIntOps::srem(Offset, APInt(Offset.getBitWidth(), Size))){ - Offset = APIntOps::sdiv(Offset, APInt(Offset.getBitWidth(), Size)); - GetElementPtrInst *GEP = - GetElementPtrInst::Create(X, Context->getConstantInt(Offset)); - // A gep synthesized from inttoptr+add+ptrtoint must be assumed to - // potentially overflow, in the absense of further analysis. - cast<GEPOperator>(GEP)->setHasNoPointerOverflow(false); - return GEP; - } - } - // TODO: Could handle other cases, e.g. where add is indexing into field of - // struct etc. - } else if (CI.getOperand(0)->hasOneUse() && - match(CI.getOperand(0), m_Add(m_Value(X), - m_ConstantInt(Cst)), *Context)) { - // Otherwise, if this is inttoptr(add x, cst), try to turn this into an - // "inttoptr+GEP" instead of "add+intptr". - - // Get the size of the pointee type. - uint64_t Size = TD->getTypeAllocSize(DestPointee); - - // Convert the constant to intptr type. - APInt Offset = Cst->getValue(); - Offset.sextOrTrunc(TD->getPointerSizeInBits()); - - // If Offset is evenly divisible by Size, we can do this xform. - if (Size && !APIntOps::srem(Offset, APInt(Offset.getBitWidth(), Size))){ - Offset = APIntOps::sdiv(Offset, APInt(Offset.getBitWidth(), Size)); - - Instruction *P = InsertNewInstBefore(new IntToPtrInst(X, CI.getType(), - "tmp"), CI); - GetElementPtrInst *GEP = - GetElementPtrInst::Create(P, Context->getConstantInt(Offset), "tmp"); - // A gep synthesized from inttoptr+add+ptrtoint must be assumed to - // potentially overflow, in the absense of further analysis. - cast<GEPOperator>(GEP)->setHasNoPointerOverflow(false); - return GEP; - } - } + return 0; } diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index f6d8e86850f..71e98377738 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -475,11 +475,8 @@ public: static GetElementPtrConstantExpr *Create(Constant *C, const std::vector<Constant*>&IdxList, const Type *DestTy) { - GetElementPtrConstantExpr *Result = new(IdxList.size() + 1) - GetElementPtrConstantExpr(C, IdxList, DestTy); - // Getelementptr defaults to having no pointer overflow. - cast<GEPOperator>(Result)->setHasNoPointerOverflow(true); - return Result; + return + new(IdxList.size() + 1) GetElementPtrConstantExpr(C, IdxList, DestTy); } /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index c1b57a6e1e4..e04d54cee37 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -1023,9 +1023,6 @@ void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx, OL[i+1] = Idx[i]; setName(Name); - - // GetElementPtr instructions have undefined results on overflow by default. - cast<GEPOperator>(this)->setHasNoPointerOverflow(true); } void GetElementPtrInst::init(Value *Ptr, Value *Idx, const std::string &Name) { @@ -1035,9 +1032,6 @@ void GetElementPtrInst::init(Value *Ptr, Value *Idx, const std::string &Name) { OL[1] = Idx; setName(Name); - - // GetElementPtr instructions have undefined results on overflow by default. - cast<GEPOperator>(this)->setHasNoPointerOverflow(true); } GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI) @@ -1049,10 +1043,6 @@ GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI) Use *GEPIOL = GEPI.OperandList; for (unsigned i = 0, E = NumOperands; i != E; ++i) OL[i] = GEPIOL[i]; - - // Transfer the hasNoPointerOverflow() value from the original GEPI. - cast<GEPOperator>(this) - ->setHasNoPointerOverflow(cast<GEPOperator>(GEPI).hasNoPointerOverflow()); } GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp index 279eabb0ec4..ab2e35c1af7 100644 --- a/llvm/lib/VMCore/Value.cpp +++ b/llvm/lib/VMCore/Value.cpp @@ -363,8 +363,6 @@ Value *Value::getUnderlyingObject() { unsigned MaxLookup = 6; do { if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) { - if (!GEP->hasNoPointerOverflow()) - return V; V = GEP->getPointerOperand(); } else if (Operator::getOpcode(V) == Instruction::BitCast) { V = cast<Operator>(V)->getOperand(0); |