summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-07-20 17:43:30 +0000
committerDan Gohman <gohman@apple.com>2009-07-20 17:43:30 +0000
commitf2411744214dad8c71044aac2977ca77e9ebf028 (patch)
treeab9b1cf7ba93de491166ef4b814f9b673ad8f2ae /lib
parent8f4e22ff9a17b750fef179ed1572e9bfd01ed9a2 (diff)
downloadllvm-f2411744214dad8c71044aac2977ca77e9ebf028.tar.gz
llvm-f2411744214dad8c71044aac2977ca77e9ebf028.tar.bz2
llvm-f2411744214dad8c71044aac2977ca77e9ebf028.tar.xz
Revert the addition of hasNoPointerOverflow to GEPOperator.
Getelementptrs that are defined to wrap are virtually useless to optimization, and getelementptrs that are undefined on any kind of overflow are too restrictive -- it's difficult to ensure that all intermediate addresses are within bounds. I'm going to take a different approach. Remove a few optimizations that depended on this flag. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76437 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp9
-rw-r--r--lib/Analysis/ScalarEvolution.cpp13
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp85
-rw-r--r--lib/VMCore/Constants.cpp7
-rw-r--r--lib/VMCore/Instructions.cpp10
-rw-r--r--lib/VMCore/Value.cpp2
6 files changed, 9 insertions, 117 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index dcb5903a14..308c69a87e 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/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/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 6c23f401c5..aadba9d9d3 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/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/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 94547b48bb..d2ed1e14e3 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index f6d8e86850..71e9837773 100644
--- a/lib/VMCore/Constants.cpp
+++ b/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/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index c1b57a6e1e..e04d54cee3 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/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/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index 279eabb0ec..ab2e35c1af 100644
--- a/lib/VMCore/Value.cpp
+++ b/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);